PHP中的$ _POST没有值

时间:2015-02-10 01:45:22

标签: php post apache2

我创建了两个php文件。第一个是encrypt.php,它将textareas发送到handleData.php。目前,这只是将输入保存到文本文件,但即使这样也行不通。文本文件保持原样,之后似乎没有传递任何数据。我也试图明确地回应数据,但它仍然是空白的。为什么帖子没有发送任何数据?我尽我所能做了一切,并命名textareas但它拒绝工作

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");                                                                                                                                                  
?>

2 个答案:

答案 0 :(得分: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">   

答案 1 :(得分: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.  

?>