is it possible to delete a 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
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

is it possible to delete a cookie?

Post by snpo123 »

hey, i have set 2 cookies that make a user logged in, and I want to create a logout page that deletes those cookies. i know i can just set all the cookies values to 0, but that has giving me complications in the past. Is there any way to delete a cookie besides just setting all its values to 0? thanks.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

http://php.net/setcookie

Example 2. setcookie() delete example, should work fine.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Marks suggestion is best but its also possible with the use of javascript. Its less efficient but works great:

javascript:void(document.cookie="")

notice im using "" to set the cookie to null.

8)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Joe's example will set all cookies available to the current page to null.. not just a specific one. be warned
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

uses marks suggestion
Post Reply