Problems deleting cookies, won't unset Problems deleting cookies, won't unset php php

Problems deleting cookies, won't unset


The manual states:

Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.

So also make sure that $path is specified correctly -- also when deleting it. For instance, if the cookie was specified in a subdirectory, you may not be able to delete it from either the parent or children directories (or both).

I'm not entirely sure how the permissions work, but you might want to use the Web Developer Toolbar to view what the path is of the cookie you are attempting to delete.


Ok, I really don't understand, but it works now. The magic code is:

setcookie("name", '', 1, $path);

Haven't I already tried that??! Whatever, it works now. Thanks for your help, people!


I'm surprised no one has mentioned it (or maybe I missed it), but domain is important too! If you are on sub-domain.example.com, and the cookie is from .example.com, then you need to explicitly set the domain parameter, otherwise it will assume the current domain and it won't work.

setcookie('cookiename', FALSE, -1, '/', '.example.com');

Sub-domains value will not clear cookies from parent domain.