Link to home
Start Free TrialLog in
Avatar of LiquidIce911
LiquidIce911

asked on

Clearing all cookies

I set cookies to remember a person who has been in my site so they don't have to type in their username and login every single time. The problem is that sometimes when I try to clear out cookies they are not deleted correctly. How can I delete all cookies related to my site from a persons computer?
Avatar of Roonaan
Roonaan
Flag of Netherlands image

<?php
foreach($_COOKIE as $name => $value)
  setcookie($name,'');
?>

Regards

-r-
Avatar of php-webdesign
php-webdesign

when you set a cookie you use +3600 for the validation time... to delete them use -3600
Avatar of LiquidIce911

ASKER

Roonaan: that will clear only cookies from MY website ?

php-webdesign: I dont want cookies to expire. Right now I use
setcookie('cookieusername', $username, time()+60 *60*24*90 ,'/','.'.$domain);  
This is a safe and easy way:

foreach ($_COOKIE as $strCookie=>$var) {
   setcookie($strCookie, "", mktime(0, 0, 0, 1, 1, 1971));
}

You may also want to consider sending your own custom expiration headers.
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I know where my problem is but I am not sure how to fix it now.
My domain seems to be conflicting somehow, when I use "/" for path and ".peoplegrade.com". It will not delete the cookie correctly even when I am using the same parameters. If I leave them blank, the cookie will work "sort of" correctly. If I go to my website as http://peoplegrade.com and login then if I visit it as http://www.peoplegrade.com as hit Logout it will not log me out. How do I fix this?
Possibly, you could force a reload as to always enter using www.peoplegrade.com.

-r-
I'm not sure why the manual says a cookie must be set to expire with the same values it was created with. It just sends a header with the cookie's expiration date included, there doesn't seem to be any relation to the previously set expiration date. Most likely there was an issue with very old browsers.
Re: Skonen:
I suppose they had the path/domain/secure arguments in mind, and not especially the time limit argument..


-r-