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

Hi,

Is there a way to remove all cookies set by one domain? Cause just like I do print "Set-Cookie: etc etc etc\n"; I would like to first have my script remove any other cookies with different names that might've been setup by the same site on the user's computer.

Any ideas?

Thanks,
Ralph

Replies are listed 'Best First'.
Re: Removing cookies
by blaze (Friar) on Jun 30, 2003 at 21:27 UTC
    from CGI::Cookie docs (in case you dont know all the names of the cookies)
    %cookies = fetch CGI::Cookie; foreach (keys %cookies) { do_something($cookies{$_}); }

    -Robert

    Hopefully there will be a witty sig here at some point
Re: Removing cookies
by cbro (Pilgrim) on Jun 30, 2003 at 20:34 UTC
    If you know the names of the cookies, you can set the expire time to a negative value. I am not familiar with deleting cookies by domain name though.
    $cookie = $co->cookie ( -name=>'sessID', -value=>\%v, -expires=>'-1h', ); print $co->header(-cookie->$cookie);

    HTH,
    Chris
Re: Removing cookies
by drfrog (Deacon) on Jun 30, 2003 at 20:49 UTC
    above is ok for removing cookie at end of browser session
    if however you want the cookie to expire on script completion try sending the cookies value as '' in the header with same name
    my $cookie = new CGI::Cookie(-name=>'cookie',-value=>''); print $q->header(-type=>'text/html', -cookie=>$cookie );
    im not sure about by domain either.. although a perl script on a domain can only effect those cookies set by that domain as far as i can recall
      Not setting an expire at all is good for deleting cookies when the browser session ends. Setting expire to a negative value will delete the cookie during the current browser session if it has been set at some other time (or during the current session). Either way, I realized after I posted that the author of this node most likely knows this already, and is only interested in deleting by domain name.