Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Deleting cookie?

by perlgrammer (Initiate)
on May 08, 2002 at 07:44 UTC ( #164943=perlquestion: print w/replies, xml ) Need Help??

perlgrammer has asked for the wisdom of the Perl Monks concerning the following question:

Could anyone please help me on how to delete cookie from browser using perl/cgi script? thanks.

Replies are listed 'Best First'.
Re: Deleting cookie?
by zakb (Pilgrim) on May 08, 2002 at 08:18 UTC

    If the cookie does not have an expiration date, it is a session cookie and will be removed when the browser closes.

    Otherwise, set the expiration date of the cookie to a date in the past and re-send it to the browser.

    See CGI::Cookie, in particular here.

(wil) Re: Deleting cookie?
by wil (Priest) on May 08, 2002 at 09:52 UTC
    If you're using CGI.pm, which is a good idea to use when writing perl/cgi scripts, you can take advantage of it's built in cookie support.

    The relevant section in the documentation states that "Negative expiration times (e.g. "-1d") cause some browsers to delete the cookie from its persistent store. This is a poorly documented feature.".

    Here's some sample code to help you delete a cookie:

    my $cookie = $query->cookie ( -name => 'foo', -value => 'bar', -expires => '-1d', -path => '/', -domain => 'my.domain.com' ); print $query->header(-cookie=>$cookie);

    - wil
Re: Deleting cookie?
by IlyaM (Parson) on May 08, 2002 at 11:43 UTC
    As alternative to setting expire time to a date in the past you can just supply empty value for the cookie. Most browsers seems to delete cookie with empty value.

    --
    Ilya Martynov (http://martynov.org/)

Re: Deleting cookie?
by Putzfrau (Beadle) on May 08, 2002 at 18:28 UTC
    When you create the cookie if you set the expires option to blank or undefined the cookie will be deleted once the browser empties its cache( ex: when it exits)thats about the only way i know how to delete a cookie using perl

    "Your baudrate depends on the size of your pipe". -ALex Simonelis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://164943]
Approved by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-12-01 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?