Forum Moderators: coopster
$canpost = 1;
setcookie("canpost", $canpost, time()+90);
if (!isset($_COOKIE['canpost'])) {
header("Location: index.php");
}
I basically want the user to be redirected to index.php if the user doesn't have cookies enabled. For some reason the above doesn't seem to work. I've been told I could detect this with javascript, but i'd rather avoid that.
Cheers,
Neil
1) user requests page (no cookies in Header)
2) the page is parsed on the server using PHP (still no cookie)
3) the server sends the page (as HTML) with a Set-cookie Header
4) the browser receives and sets the cookie as the page is loaded
At this point, the page has been generated and served but the browser has not reported any cookie information to the server so $_COOKIE is empty and the check will always be false (assuming no previous cookies).
5) all future page requests will contain the Cookie information in the Header and your code will work as expected
;)