Image

Imagesprak3000 wrote in Imagephp 😡annoyed

setcookie and IE6

Apologies if this has been covered before, but I have yet to find a definitive answer. I want to do a simple test to see if a user has cookie enabled. So, I drop this code on my login page:


session_start();
setcookie("check", "true", time() + 3600, "/");


and this code on the login process page:

session_start();
// Check to see if login cookie set. If not, redirect to warning page.
if (!isset($_COOKIE["check"])) {
setcookie("check", "", time() - 3600, "/"); // destroy the cookie
header("Location: " . $directoryLevel . "nocookie.php\r\n");
exit();
} else {
setcookie("check", "", time() - 3600, "/"); // destroy the cookie
}


I am running into some bizarre behavior on IE6:

  1. IE6 does not seem to set a cookie if the host trying to set the cookie has a '_' in it (e.g., test_foo.bar.com). A comment in the setcookie PHP doc page confirms that I am not alone in this problem. Is there any workaround/fix for this?
  2. On normal hosts with no '_', the cookie does not get set on a very small set of my IE6 users. When I run IE6 at work and at home, I cannot reproduce the problem; the check cookie is always being set. However, some users claim to have IE6 setup to accept all cookies, but the check cookie is never set.


I have tried all of the examples on the setcookie PHP doc page with no success. Is there a definitive solution for testing via PHP that a user has cookies enabled that works with IE6?

Thanks.