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

i want to delete all the cookies set by a given domain. how i do this? dont want to delete any other cookies, just the specified domains.

Replies are listed 'Best First'.
Re: delete cookies
by little (Curate) on Oct 03, 2000 at 00:18 UTC
    Refer to the amn pages for CGI::Cookie or HTTP::Cookie. Following is an excerpt from first.
    fetch returns an associative array consisting of all cookies returned +by the browser. The keys of the array are the cookie names. You can i +terate through the cookies this way: %cookies = fetch CGI::Cookie; foreach (keys %cookies) { do_something($cookies{$_}); } value() Get or set the cookie's value. Example: $value = $c->value; @new_value = $c->value(['a','b','c','d']); value() is context sensitive. In an array context it will return the c +urrent value of the cookie as an array. In a scalar context it will r +eturn the first value of a multivalued cookie. expires() Get or set the cookie's expiration time.
    So try to get all cookies and set their expiration time to not specified (e.g. by setting the value to the number zero), though the cookie will be deleted after session ends. But only the server who wrote a cookie can have access to it :-)

    Have a nice day
    All decision is left to your taste
      huh? still confused but this wont make me find the cookie file for the browser. so i say %cookies = fetch CGI::Cookie; foreach (keys %cookies) { expires(0) } ?
Re: delete cookies
by Fastolfe (Vicar) on Oct 03, 2000 at 00:12 UTC
    You can't do it for all cookies set at a given domain. You need to refer to each cookie by name and specify an Expired value that's in the past. If all of the cookies you set have a proper Expired time (if it needs one; session-only keys are quite useful), you don't have to worry about deleting it later. (Update: I guess that first sentence wasn't 100% accurate.. you *can* use the list of cookie names that the browser provided your script, but of course this will not include cookies that have a path specified that differs from where your script is located, or for cookies that are off-site.)

    Of course, I'm assuming this is a Perl + CGI question.. If you're asking how to delete cookies on your local system, you'd need to iterate through the various files or folders where the cookies are stored and delete them from there. Each browser does it differently. If this is what you're asking for, perhaps somebody else has a better answer.

Re: delete cookies
by fundflow (Chaplain) on Oct 03, 2000 at 00:13 UTC
    Do you mean something like:
    grep -v "this.domain" cookies > new-cookie-file
    Or:
    perl -pe 'print unless /this.domain/' cookies > new-cookie-file
      huh? what cookie file? im so confused.
        Oh, sorry.
        In case you are using netscape (the other browsers might be different) you should find a file called 'cookies' somewhere in your system. On unix, it is in ~/.netscape/cookies.

        After you find this file, you can just erase the lines that you don't like. Either with a text editor or with perl.

        If you are the original poster, perhaps you can provide us with some more information about your question:
        • Is this a CGI question? Are you wanting a CGI script to clear cookies that it has set in the past? Are you wanting a CGI script to clear cookies set by other areas of your web site?
        • Is this a Windows question? Are you wanting to clear a set of cookies in Internet Explorer? Netscape?
        • Is this a Unix question? Are you wanting to clear a set of cookies out of Netscape or another browser?
        Give us more information.