Hi,
I am having some trouble with testing that a cookie
has already been set. As a test, if I type the following
URL into my browser:
http://www.mydomain.com/index.php?id=jack
.....what happens is that a cookie gets set correctly (I check
to see that the cookie is created in my browser.)
Now, the problem is if I type the following URL into my browser
immediately after this:
http://www.mydomain.com/index.php?id=jill
...I would expect to see the message about not being able to
create the cookie as it already exists but this doesn't happen,
instead the existing cookie (id=jack) gets overwritten with
the second cookie (id=jill).
I am obviously doing something fundamentally wrong but I just can't
see it - can anyone help?
Here my simple index.php code:
<== SNIP ==>
<?php
$cookiename = 'KILLER'; // Cookie name
$cookiedays = '365'; // Nbr of Days before cookie will expire
$domain = 'mydomain.com'; // Domain cookie is applicable for
if(!isset($_COOKIE['$cookiename']))
{
setcookie($cookiename, $id, time()+606024*$cookiedays, "/", ".$domain");
} else {
print "Can't create cookie as this cookie already exists!";
}
?>
<HTML>
<HEAD>
<TITLE>Cookie Test</TITLE>
</HEAD>
<BODY>
Normal content in here!
</BODY>
</HTML>
<== /SNIP ==>
Thanks,
Adam