Cookies

lord_spaceman

Expert Member
Joined
Jun 6, 2005
Messages
1,470
Reaction score
0
Location
Durban
Is there a way in PHP (or javascript) to test if a browser has cookies disabled ? And if so, display a message.

A feature I'm building requires cookies to work and if cookies are disabled, I want to disable the feature.
 
Probably not PHP, because it executes on the server (you want it to execute in the browser), so JavaScript. I'm not sure what you want to do. I don't know if there's a unified standard in browsers for checking this (...knowing IE). The easiest (for me) would be to set a test cookie, and then try to retrieve it. If the script manages to retrieve the cookie it set, cookies are most probably enabled.

This might help: http://www.w3schools.com/js/js_cookies.asp

Of course, there is probably a better way...
 
Why not just set a cookie in php, and then try and retrieve it...
Code:
if(isset($_COOKIE['cookieSet'])){
 $redirect="cookiepage.php"
} else {
 $redirect="non-cookiepage.php"
}

You'll probably need to refresh the page to test for the cookie, I found a code sample here:
http://www.zend.com/codex.php?id=8&single=1
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X