Reputation: 126102
From PHP, I'm having trouble getting the browser to delete a cookie. To chase down the problem, I have created a simple test page that just does this:
// Set cookie named MrPants with value foo to expire at end of session
setcookie("MrPants", "foo", 0);
After loading that page, I see the cookie in my Firefox cookies menu. So far, so good.
Then I follow example #2 here to delete a cookie:
// Set that cookie's expires time in the past
setcookie("MrPants", "", time() - 3600);
This has no effect. I have tried specifying the path, too; no change.
In Firebug, I see the following in the response headers:
Set-Cookie ZDEDebuggerPresent=php,phtml,php3; path=/
MrPants=deleted; expires=Tue, 25-Aug-2009 15:27:46 GMT; path=/some/path
What am I missing here?
Upvotes: 0
Views: 1123
Reputation: 5620
Check the domain. You can have multiple cookies with the same name and different domains (e.g. one is set on home.foo.com another on the root .foo.com). Deleting one doesn't delete the other.
Upvotes: 0
Reputation: 126102
Hmmm, actually the cookie IS being deleted. I appear to have found a quirk in Firefox 3.5.10 (Fedora Linux).
I went into Preferences > Privacy > remove individual cookies and searched for the cookie name. When it's added, it appears in that window, but when it's deleted, it doesn't disappear from that window. You have to close the window, re-open it, and search for the cookie again.
Even worse, if the cookie is deleted and re-added in the same script, it shows the new cookie appearing without the old one disappearing - multiple cookies with the same name and path! That was really freaking me out.
I haven't filed a bug on this, but if anyone else wants to, be my guest.
Upvotes: 0