Code used to set cookie:
setcookie("adminloggedin", "yes", time()+86400, "/admin/", $cookie_domain);
Code used to destroy:
setcookie("adminloggedin", "", time()-86400, "/admin/", $cookie_domain);
Why doesn't it destroy the cookie?
Originally posted by Sharif Why doesn't it destroy the cookie?
I don't believe you've asked it to. Only to set its value to null.
How are your testing the cookie?
Also, have your tried
<? unset($_COOKIE['adminloggedin'];
Well by reading the manual, I thought the only way to destroy a cookie was to give it a blank value and set the time backwards...
Hmm, yeah, I see that.
How do you know that the cookie's not destroyed?
<?php // should echo "value of blah set via the blahcookie" after *reload* setcookie("blahcookie", "blah"); if ($_COOKIE['blahcookie']) { echo "value of ".$_COOKIE['blahcookie']." set via the blahcookie!</td>\n"; } else { echo "no blahcookie!</td>\n"; } ?> <?php // should echo "no blahcookie!" after *reload* setcookie("blahcookie", ""); if ($_COOKIE['blahcookie']) { echo "value of ".$_COOKIE['blahcookie']." set via the blahcookie!</td>\n"; } else { echo "no blahcookie!</td>\n"; }?>
I'm doing the exact thing in your example but just with a different script. I never get the message I'm supposed to if I the cookie doesn't exits.
Try not giving it special values like '/admin/' and the one after it. Just use
setcookie( "adminloggedin", "", time()-60 );
I've had the same problem, but haven't been able to find a resolution anywhere. Did you ever find a solution?
According to the PHP manual, "Cookies must be deleted with the same parameters as they were set with." But even so, I can't get some of my cookies to go away.
I never found a solution 🙁
Yeah, but if you set the cookie value to NULL then it cannot read from the cookie, and even if it does not delete it then, it won't beable to read from it.