我有一个简单的 PHP 页面,它为 3 个 URL 设置 cookie。问题是,即使我从未发送过任何标头信息,我仍然会收到标头错误。如何编写下面的 PHP 而不会出现这些错误?
完整的PHP代码:
<?php
if ($_GET["validate"] == 1)
{
setcookie("siteaccess", "AccessGranted", time()+(36*1*1), "/", "b********.com", 0); //Access granted
setcookie("siteaccess", "AccessGranted", time()+(36*1*1), "/", "b********.net", 0);
setcookie("siteaccess", "AccessGranted", time()+(36*1*1), "/", "b********.zxq.net", 0);
$page = urldecode($_GET["preturn"]);
echo '<meta http-equiv="Refresh" content="0;' . $page . '">';
}
else
{
echo "Illegal page access";
}
?>
页面加载时出错:
Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/b/i/t/bitfracture/htdocs/authenticate.php:2) in /www/zxq.net/b/i/t/bitfracture/htdocs/authenticate.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/b/i/t/bitfracture/htdocs/authenticate.php:2) in /www/zxq.net/b/i/t/bitfracture/htdocs/authenticate.php on line 5
Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/b/i/t/bitfracture/htdocs/authenticate.php:2) in /www/zxq.net/b/i/t/bitfracture/htdocs/authenticate.php on line 6
页面加载时的 URL:
http://b*******.com/authenticate.php?preturn=%2Fcaptcha%2Findex.php&validate=1
进一步说明:此页面为我的网站可以访问的所有 3 个 URL 设置了一个 cookie。此页面在用户完成简单的反机器人测试后加载,以防止机器人向我的下载计数器发送垃圾邮件。设置 cookie 后,此页面会将您重定向回最初将您发送到此处的页面,并且由于 cookie 应该在此之后就位,用户将不再看到身份验证验证码。
如果我需要提供更多信息,请告诉我。我只需要让这些错误消失,这样我就可以正确设置 cookie。