Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems deleting cookies, won't unset

Tags:

php

unset

cookies

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?

like image 950
RemiX Avatar asked May 18 '10 10:05

RemiX


People also ask

Why are my cookies not deleting?

Your cookie is most likely not being deleted because when you set the new value, it has to match the path and domain of the original cookie you're trying to delete. that "something" value needs to line up with whatever the existing cookies have set.

Why do my cookies keep coming back after I delete them?

If bad cookies keep making their way back onto your company computer after a scanner removes them, it is because your Web browsing keeps inviting the cookie back.

Why can I not delete cookies in Chrome?

Open chrome://settings/ Click "Show advanced settings ..." Navigate down to System section and disable "Continue running background apps when Google Chrome is closed". This will force Chrome to close completely and then it will delete session cookies.


1 Answers

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.

like image 65
Paul Lammertsma Avatar answered Sep 20 '22 19:09

Paul Lammertsma