Page 1 of 1

[SOLVED] Cookie question

Posted: Mon Jul 26, 2004 11:59 am
by evilmonkey
Hello everyone.

I have a question regarding a cookie. When a cookie is set, using setcookie() in PHP, and an expiry date is set (to one year from now), the data in the cookie is easily read by PHP and passed to whereever it needs to be passed. For example:

Code: Select all

<?php setcookie("cookiename", $sessid, time()+60*60*24*30*12, "/"); ?>
Now, my question is, what happens when I do something like this?

Code: Select all

<?php setcookie("cookiename", "",  time()-3600); ?>
After this command is run, if I do a check on the cookie (such as if (isset($_COOKIE['cookiename']))), should that condition still pass? In other words, is the cookie still set?

Thanks!

Posted: Mon Jul 26, 2004 12:07 pm
by PrObLeM
1st ... try it your self it wont hurt to see if it works or not

2nd... i believe the cookie will be unset so the if (isset($_COOKIE['cookiename'])) will return false

Posted: Mon Jul 26, 2004 12:11 pm
by evilmonkey
I tried it out,I got that the cookie is still set, and was wondering if this is normal behaviour. I'll go back to my code, see if I missed something. Thanks!

Posted: Mon Jul 26, 2004 12:14 pm
by evilmonkey
OH DARN!!!

I just remebered something. The page needs to be refreshed in order for the cookie information to change right? That was my downfall. The code is fine. :D

Thanks!

Posted: Mon Jul 26, 2004 4:29 pm
by tim
lol a refresh is a needy =]