Page 1 of 1

Cookie not deleted when using domain

Posted: Tue Jul 09, 2002 1:12 pm
by proteus
Hello,

I have a problem and I hope someone can enlighten me. I am using the following code to set a cookie:

Code: Select all

setcookie("member", $aї'name'], time()+86400, "/", "$cookie_domain");
Where $cookie_domain is like ".domain.com"

The coookie is set OK, but I can't seem to be able to delete it:

Code: Select all

setcookie("member","",time()-3600,"/","$cookie_domain");
If I don't specify a domain when setting a cookie, I can delete it very well. But I need to use domain, as I never know what the user will use to enter the site (http://www.domain.com, server.domain.com etc.), and I want the cookie to be recognized on different visits, regardless of what URL will be used.

Any help is greatly appreciated.

Best regards,
Sebastia

Posted: Tue Jul 09, 2002 4:20 pm
by mikeq
What you have should work fine.

Have you made sure that what you have in $cookie_domain is what you expect. Try first off by hard coding the domain see if that deletes the cookie.

Posted: Wed Jul 10, 2002 1:07 am
by proteus
Yes, I'm sure the domain is OK. I checked both in the program and in the browser, to see what cookies are stored.

This is really strange. 8O

Best regards,
Sebastian

Posted: Wed Jul 10, 2002 6:12 am
by mikeq
Okay but do a

Print "The domain is $cookie_domain";

before the bit that is supposed to delete the cookie, PHP will give an error about headers already being sent but just ignore this, the print statement will also be output to the browser.

Mike

Posted: Wed Jul 10, 2002 6:22 am
by proteus
Damn! You were perfectly right!

Indeed, I was checking to see if the $cookie_domain is set when sending the cookie, but not when deleting.

The source of error was a typo in a require_once(), which was loading the wrong config variables.

It's funny how sometimes one can miss the obvious. Sorry for wasting your time and thank you for your help.

Regards,
Sebastian

Posted: Thu Jul 11, 2002 3:22 am
by mikeq
proteus wrote:Sorry for wasting your time and thank you for your help.
It's okay thats what we are here for, glad I could help.

Mike