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

Hello all,

How would I create code to get all of the cookies that a browser contains? What I want are all of the authentication cookies set by different parts of our site. I'm making a tech support page that will get all that browser info without me having to ask em.
_______________________________________________
"Intelligence is a tool used achieve goals, however goals are not always chosen wisely..."

Replies are listed 'Best First'.
Re: Ma, I want all the cookies...
by merlyn (Sage) on Jan 09, 2001 at 21:28 UTC
    All the cookies you're ever gonna get are sent on every transaction. So, to list them, use code something like:
    use CGI qw(:all); print header, start_html("cookie lister"), h1("cookies"); for (cookie) { print escapeHTML($_), " has value ", escapeHTML(join ", ", cookie($_ +)), br; } print end_html;

    -- Randal L. Schwartz, Perl hacker

Re: Ma, I want all the cookies...
by extremely (Priest) on Jan 10, 2001 at 03:27 UTC
    Cookies can be set to various domain levels. Thus, cookies on www.this.domain.ext could be set to 'www.this.domain.ext', 'this.domain.ext' or 'domain.ext'. Cookies set to higher levels won't be visible on a different domain like 'www.that.domain.ext'! It will only see cookies set to 'domain.ext'. As merlyn said, they are sent everytime a request is made and all the ones you will ever see where you are, will be there. There is no way to get it so send the others.

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: Ma, I want all the cookies...
by $CBAS (Scribe) on Jan 10, 2001 at 01:38 UTC

    Take a look at the $ENV{COOKIE} or $ENV{HTTP_COOKIE} scalars, they hold the crap that's coming from the browsers.

    What I do is I use CGI::Cookie but it's hella slow because it loads a shitload of code (takes ~0.2s to load on my PII 266 running IIS5 and ActivePerl 5.6)

    If you're looking for more client information, you'd be better off using some JavaScript code to send everything to your script in a query string, like most counters do. There's also some general stuff in %ENV but maybe others here know better ways to get kinky information form users?

    Rock on,
    CBAS