Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie Destruction

Status
Not open for further replies.

dozier

MIS
Apr 17, 2001
88
US
I'm playing around with using cookies, and I have a question. How does one "get rid of" a cookie before its expiration? I'm using a cookie to store login information, but what if the user decides they no longer want the site to remember their info? Thanks.
 
You simple set the cookie to a null value and that will remove the cookie.

 
I assume you mean something like this:

$cookie = $co->cookie
(
-name=>'login_cookie',
-value=>'',
);

print $co->header(-cookie=>$cookie);

But that didn't work.
 
Yes that is correct. But remember how cookies work. You have to re-invoke the script to get the server to resend the new empty cookie. You make need to send them to a simple redirect page to get it to reload the script and pick of the empty or non-existance cookie.
 
Try this little debuggin trick

$cookie = $co->cookie
(
-name=>'login_cookie',
-value=>'', <---use double quotes
);

print $co->header();<---remoive when done
print $co->header(-cookie=>$cookie);

Now you can see what the cookie is being set to.
It should look like this..

Content-type: text/html
Set-Cookie: ITEMS=; path=/your/path/; domain=
 
It's also a good idea to set the cookie expiration date to some day in the past. That will pretty much guarantee it will be deleted regardless of whether it has a value or not.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top