I am trying to a show a message on the screen if cookies are disabled on the browser. The code I am using is this
"
setcookie(‘test’, 1, time()+3600);
if(count($_COOKIE) > 0){
echo "Cookies Enabled ";
} else {
echo "Cookies Disabled ";
}
"
The problem is that this works fine in Firefox on my PC but Doesn’t work in IE 8 or safari even if the cookies are enabled on the browsers. Plus it works fine on my co worker’s PC in all browsers.
Would appreciate any help.
Thanks
Cookies are passed in HTTP headers so they’re not accessible until the next page load after setting them.
"http://php.net/manual/en/function.setcookie.php":
Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays
Also take care of the time + 3600 , if somebody have his PC time long after the server time… the cookie will be considered expired.
i am not quite sure, but i think you should get that time() not from the server, but from the user PC using javascript!?