2014-09-01 46 views
0

这是我的代码。answer.php无法正常工作

<?php 
header ('Location: example.com'); 
$handle = fopen("entry.txt", "a"); 
foreach($_POST as $variable => $value) { 
    fwrite($handle, $variable); 
    fwrite($handle, "="); 
    fwrite($handle, $value); 
    fwrite($handle, "\r\n"); 
} 
fwrite($handle, "\r\n"); 
fclose($handle); 
exit; 
?> 

我希望它在单独的.txt文件中记录输入的答案,但它不这样做。相反,它打开“entry.txt”并留下空白空间。

任何线索可能是什么问题?我一直试图解决这个问题近一个小时。

回答

0

您的代码正常工作。您可能需要chmod您的文件才能拥有写入权限,因为它可能设置为666或更多。

此外,当您尝试重定向到不同的域时,您必须添加该协议;否则,标题()会送你到http://yourdomain.com/example.com

// WRONG 
header ('Location: example.com'); 

// RIGHT 
header ('Location: http://example.com/'); // Trailing slashes are a good habit 
0

使用is_writable($文件名)首先检查文件是可写的。