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?
Did you check if your script already send its HTTP headers?
Just define a custom function in global core functions file like global.php
and use this function at the top of the html code like
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.
Sub-domains value will not clear cookies from parent domain.
The manual states:
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.
Have you tried setting the time to a small value and using a value for cookie?