Page 1 of 1

[SOLVED] Firefox - Deleting Cookies

Posted: Fri Aug 27, 2004 2:42 pm
by RadixDev
OK I have the following code to delete cookies:

Code: Select all

<?php
setcookie("id","",time()-3600);
setcookie("usr","",time()-3600);
unset($_COOKIE['id']);
unset($_COOKIE['usr']);
?>
This works perfect in IE, but doesn't work in firefox. Any ideas?

Posted: Fri Aug 27, 2004 2:49 pm
by feyd
path, domain, and secure flag need to match the original cookies exactly. You may want to set the expire time to a bit farther in the past.. I generally do a week or month or more.

Posted: Fri Aug 27, 2004 5:12 pm
by RadixDev
Well soon as I didn't touch the cookies, the details should not matter. I changed the time to a week and to a month ago but no luck... any other ideas? I mean it works in IE how come it doesn't work in Firefox?! :roll:

Posted: Fri Aug 27, 2004 5:55 pm
by feyd
I've never had to call unset on cookies to delete them.. maybe the cookies were set to a different domain and/or path?

Posted: Sun Aug 29, 2004 2:55 am
by RadixDev
how do you mean different path? If the domain is the same I should be able to delete cookie right? Or should set the value to NULL?

Posted: Sun Aug 29, 2004 3:23 am
by feyd
if the path varies between the original cookie and the "delete" cookie.. a new cookie is often created.

Posted: Sun Aug 29, 2004 5:17 pm
by RadixDev
OK here's the code I use to make cookie:

Code: Select all

<?php
setcookie('usr',$usr,time()+2592000,'/','radix-dev.com');
setcookie('id',$var,time()+2592000,'/','radix-dev.com');
?>
And here's the one to destroy them:

Code: Select all

<?php
$_COOKIE['usr']	= NULL;
$_COOKIE['id']	= NULL;
setcookie("usr","",time()-2419200,"/");
setcookie("id","",time()-2419200,"/");
unset($_COOKIE['id']);
unset($_COOKIE['usr']);
?>
Tried it without setting the variables to NULL - doesnt work.
without unset() doesn't work... any ideas? By the way I am calling the
delete cookie thing from /lounge/logout.php and setting the cookie at /library/usrmanage.php.

Posted: Sun Aug 29, 2004 8:24 pm
by m3mn0n
Copy and paste the code that sets cookies, and make the time a negative instead of a positive.

Posted: Mon Aug 30, 2004 1:57 am
by RadixDev
It worked!!! Cheers :D