I am trying to set a cookie using the following code:
--
if (!isset($HTTP_COOKIE_VARS['mycook']))
{
$mycook = md5(uniqid(rand()));
setcookie("mycook", $mycook, time() + 3600);
}
The cookie is set correctly because I can see the random value through echo($mycook). I have placed this setcookie() code at the top of each page in my site. I am under the impression that this will set a cookie only if the cookie doesn't already exist. The problem is, when I echo the value of the $mycook variable from each page, it is always different.
In the PHP manual it says that setcookie() will always replace cookies by the same name if they are from the same domain/path. On my site, I've got about 4 sections, each with its own directory:
ie: /
/section1/
/section2/
and so on. Does that property of setcookie() have anything to do with me? Wouldn't $mycook be passed on to each page anyway?
Thanks,
Prasanna