I have a simple PHP page that sets cookies for 3 URLS. Problem is, even though I never sent any header information, I still get header errors. How can I write the PHP below without getting these errors?
Complete PHP code:
<?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";
}
?>
Error when page loads:
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 at page load:
http://b*******.com/authenticate.php?preturn=%2Fcaptcha%2Findex.php&validate=1
Further explanation: This page sets a cookie for all 3 URLS that my site can be accessed from. This page is loaded after the user completes a simple anti-robot test, made to prevent robot spamming of my download counters. Once the cookies are set, this page redirects you back to the page that sent you here in the first place, and since the cookies should be in place after that, the user will no longer see the authentication captchas.
Please let me know if I need to provide more information. I only need to get these errors to go away so I can set cookies correctly.