Delete Cookie?

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
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Delete Cookie?

Post by InternetX »

How can I delete a cookie that I set before with setcookie(...)?
A new cookie with the same name doesn't kill the old cookie :(
Can anyone help me?

Sorry 4 my english... I'm 14 and from Germany...
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Simply set the cookie's value to nothing.
Image Image
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

set the cookie again but change the time to a negative value so it expires
e.g.

setcookie ("TestCookie", $value,time()+3600); /* expire in 1 hour */

setcookie ("TestCookie", $value,time()-3600); /* expired 1 hour ago*/
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

setcookie():
When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser.
Don't forget that you need to refresh the page before you can test for the existance or lack of the cookie.

Mac
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

I already have test this...
But my cookie will not be deleted :(

I will test it again... thanks for help :)
Post Reply