Hi Chaps,
Quick question on this one, I've got a <noscript> tag in my HTML to check to see if Javascipt in enabled, but how do you check to see if cookies are enabled?
Is there HTML code / PHP function, or do you simply try to set a cookie and redirect on failure to read the cookie you just to to set?
Cheers
No Cookie Redirect
Moderator: General Moderators
Re: No Cookie Redirect
If someone has cookies disabled then not only will 99% of the Internet not work for them, they'll probably have JavaScript disabled too (accounting for the other 1%).
1. You can't check if setting a cookie succeeded in PHP
2. You can't rely on JavaScript to set a cookie
There are a few ways to check - not all perfect - but most tend to involve (a) setting a cookie and (b) loading a page specifically designed to look for the cookie you just set. A rough example:
1. You can't check if setting a cookie succeeded in PHP
2. You can't rely on JavaScript to set a cookie
There are a few ways to check - not all perfect - but most tend to involve (a) setting a cookie and (b) loading a page specifically designed to look for the cookie you just set. A rough example:
Code: Select all
if (isset($_GET["cookie"]) && !isset($_COOKIE["foo"])) {
// probably has cookies disabled
} else if (!isset($_COOKIE["foo"])) {
setcookie("foo", "bar", $etc);
header("Location: /path/to/this/file.php?cookie=");
exit;
}-
koolsamule
- Forum Contributor
- Posts: 130
- Joined: Fri Sep 25, 2009 10:03 am
Re: No Cookie Redirect
Coolio . . .I'll give that a go, many thanks!