View Full Version : Nocookie traffic redirect?

04-22-2011, 10:48 PM
Is it possible to redirect users which dont have support for cookies to set url?
I know you can done for users which coming for first time but that is made for users which have support for cookies while in this case it should simply redirect users which dont have support for cookies.

04-22-2011, 10:59 PM
The only way I see this working is if you attempt to set a cookie, reload the page (cookies only exist on the next page load), check for the cookie you set previously, if it isn't there redirect to the non cookie page.

04-25-2011, 01:44 AM
I did this code:

$value = "my cookie value";
setcookie("user","$value", time() + 604800);
if (!isset ($_COOKIE['user']))
header ("Location: nocookie.php");
header ("Location: foundcookie.php");

And seems you are right,it works only after reload.Perhaps is there another way to detect noocookie browser?

04-25-2011, 02:25 AM
Well the php.net manual has this function


But it can only tell you if the browser is capable of accepting cookies but not if the user has this enabled or not. They say the only way to check is the way that you have discovered.

Another possibility which would involve javascript (using ajax).

You set a cookie with javascript, talk to a php script using ajax, the script can now check for the cookie (without reloading) as the call to the php script is the "reload". The php will echo true or false depending on if the cookie was set. The only problem is this won't work if the user has javascript disabled.

04-25-2011, 02:59 PM
The only problem is this won't work if the user has javascript disabled.

In which case you could redirect to the no-cookie page by default. Which leads to the thought that you’d actually provide the no-cookie page by default and then redirect to the page using cookies if they are enabled.