Page 1 of 1

Clearing Cookies without knowing the names

Posted: Wed Feb 21, 2007 3:41 pm
by yesmaster
Hey guys,
First time posting. Anyone know a way to clear out all the cookies under / without knowing the exact names? The only way I found to clear a cookie is by using setcookie(), but you have to konw the exact name.

I tried clearing the cookies by clearing the array $_COOKIE but that didn't work. Any info appreciated.

Posted: Wed Feb 21, 2007 3:58 pm
by volka
You can retrieve the names from $_COOKIE and use them with setcookie().

Code: Select all

foreach($_COOKIE as $name=>$value) {
	setcookie(...

Posted: Wed Feb 21, 2007 4:10 pm
by yesmaster
Thanks. I remember trying this but don't remember having the desired outcome, not sure the details.

What if you don't know the path, in setcookie?
For example

foreach($_COOKIE as $name=>$value) {
setcookie($name, '', time()-42000, '/');
}

So this would clear all the cookie values that were set under path '/'

Would it clear all the cookie values under /aaa/bbb/cc as well?
The manual was not so clear on this.

Posted: Wed Feb 21, 2007 4:16 pm
by feyd
That wouldn't be all that hard to test... ;)