I've tried searching the php manual and internet on how to delete cookies and I've tried it the exact same way they all say:
setcookie("name", '', 1);
or
setcookie("name", '', time()-3600);
But when I check the cookies in the cookies dialog in Firefox, it's still there with the same value. I set this cookie using the following line:
setcookie("name", $value, time() + 259200, $path);
I found this question on stackoverflow: , but none of the answers solved the problem. I also tried putting all paramaters in, like the author said, but it had no effect.
Does anyone see the problem?
Happens to me as well one in ten times though. I guess its a problem with the way we code.
This is my code
Sometimes you saved the cookie in a different path than you're trying to delete/uset it in.
Go into eg. Chrome cookie settings and check the cookie path, then add the path to the setcookie command, and delete it like this:
Trying to delete or unset a cookie that is saved in the wrong path will not work and can be very frustrating.
I tried using
and on my server with Apache/PHP5 it cleared the cookie (at least a var_dump($_COOKIE) showed an empty array).
If you delete cookie for the specific path and your path parameter ends with the trailing slash '/' then it will work in Firefox and IE, but won't work in Chrome and Opera. If there is no trailing slash then it will only work in Chrome and Opera.
So you should use both:
Ok, I really don't understand, but it works now. The magic code is:
Haven't I already tried that??! Whatever, it works now. Thanks for your help, people!
I had a similar issue.
I found that, for whatever reason, echoing something out of logout.php made it actually delete the cookie: