[SOLVED] Firefox - Deleting Cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

[SOLVED] Firefox - Deleting Cookies

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if the path varies between the original cookie and the "delete" cookie.. a new cookie is often created.
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Copy and paste the code that sets cookies, and make the time a negative instead of a positive.
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Post by RadixDev »

It worked!!! Cheers :D
Post Reply