2015-02-10 35 views
-1

我创建了两个php文件。第一个是encrypt.php,它将textareas发送到handleData.php。目前这只是将输入保存到文本文件中,但即使这样也行不通。文本文件保持原来的状态,并且后期似乎没有传递任何数据。我也尝试过显式回显数据,但它仍然是空白的。为什么帖子不发送任何数据?我所做的一切都是正确的,据我所看到并命名文字区域,但它拒绝工作

encrypt.php

<form method="POST" action="handleData.php">                                 
    <p><textarea name="plaintext" placeholder="Enter text to encrypt" rows="10" cols="50"><?php echo exec("cat input.txt")?></textarea></p>          
    <p><textarea name="ciphertext" placeholder="Enter text to decrypt" rows="10" cols="50"><?php echo exec("cat output.txt")?></textarea></p>          
    <p><input type="submit" value="Encrypt/Decrypt" onClick="location.reload()"></p>                        
</form> 

handleData.php

<?php                                             
    $num = "3128342308234";                                       

    $plain = (isset($_POST['plaintext'])) ? htmlspecialchars($_POST['plaintext']) : 'test';                       
    $cipher = (isset($_POST['ciphertext'])) ? $_POST['ciphertext'] : '';                            
    echo $_POST['plaintext'];                                       
    exec("$plain >> input.txt");                                      
    $command = "encryptPoly ".$num." ".$plain;                                   
    exec("rm output.txt");                                        
    exec($command." >> output.txt");                                     
?> 
+0

我试图让这个使用PHP工作,但我结束了使用Python的网络模块,能够做到这一点更容易。尽管谢谢你的帮助。 – zlittrell 2015-02-12 04:36:35

回答

0

你重新加载页面,因此不提交,

<p><input type="submit" value="Encrypt/Decrypt" onClick="location.reload()"></p> 

只需删除onClick:

<p><input type="submit" value="Encrypt/Decrypt"></p> 

并确保此操作与当前文件名称相同。

<form method="POST" action="handleData.php"> 
+0

问题是,您正试图在重新加载当前数据时将数据发送到单独的页面,请尝试删除onclick事件。 – 2015-02-10 01:55:18

+0

我正在使用单独的页面更新文本文件,然后通过php代码“exec(”cat output.txt)“显示在原始文本文件中。”onClick是否会导致POST不发送? – zlittrell 2015-02-10 04:53:48

+0

正如我所说在回答'你正在重新加载页面,因此不提交',通过添加你自己的'onClick'事件,你正在删除默认动作。 – 2015-02-10 11:16:22

0

你可以试试这个:

<?php                                             
$num = "3128342308234";                                       

$plain = (isset($_POST['plaintext'])) ? htmlspecialchars($_POST['plaintext']) : 'test';                       
$cipher = (isset($_POST['ciphertext'])) ? $_POST['ciphertext'] : '';                            
echo $_POST['plaintext'];                                       
exec("$plain >> input.txt");                                      
$command = "encryptPoly ".$num." ".$plain;                                   
exec("rm output.txt");                                        
exec($command." >> output.txt");                                     
?> 

到:

<?php                                             
$num = "3128342308234";                                       

$plain = (isset($_POST['plaintext'])) ? htmlspecialchars($_POST['plaintext']) : 'test';                       
$cipher = (isset($_POST['ciphertext'])) ? $_POST['ciphertext'] : '';                            
echo $_POST['plaintext'];                                       
exec("$plain >> input.txt");                                      
$command = "encryptPoly ".$num." ".$plain;                                   
exec("rm output.txt");                                        
exec($command." >> output.txt"); 

header('Location: ' . $_SERVER['HTTP_REFERER']);// Go back to previous page. 

?> 
+0

我试过这个,它什么都没做。还删除onClick只是让页面不刷新现在,POST仍然不起作用 – zlittrell 2015-02-11 02:05:15