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

I read the perlman on cookies, but I still don't understand it completely, so I was wondering if someone could tell me the code for a cookie with this info:

name: userid
value:(a veriable $reflog)
date: the current date
expires: (when browser is closed)
domain: www.theunixplace.com
path: /html

sorry, if this has been answered elsewhere, but it would take me a week or two to look at all the answers, and I would like to get this done ASAP.

Replies are listed 'Best First'.
(Ovid - use CGI.pm) Re: Cookie Code
by Ovid (Cardinal) on Apr 25, 2001 at 03:14 UTC
    From the CGI docs:
    #!/usr/bin/perl -wT use strict; use CGI; my $query = CGI->new; my $cookie = $query->cookie(-name =>'sessionID', -value =>'xyzzy', -expires =>'+1h', -path =>'/cgi-bin/database', -domain =>'.capricorn.org', -secure =>1); print $query->header(-cookie=>$cookie);
    See perldoc CGI for complete information on how to use this.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Yes, use CGI;. I did not, since I ripped that line out of my Mapster program, and edited it a bit.

      Mapster doesn't use CGI; because the server is extremely loaded, and it doesn't use mod_perl or anything. I tested on my machine, and it took about a second to load Perl plus the CGI module, and Mapster doesn't actually need to do much decoding with the parameters, so I decided to leave it out.

        It sounds like you are running it as a CGI program rather than mod_perl because you have the impression that this is more efficient.

        I hope I am seriously misunderstanding you because the entire point of mod_perl is that it is a lot faster than raw CGI.

Re: Cookie Code
by orkysoft (Friar) on Apr 25, 2001 at 02:34 UTC

    It will take you a week or three to get a good answer on an FAQ question, but in the interest is amity, I'll provide you with an example cookie header.

    Set-Cookie: counter=$count; expires=Tue, 01-Jan-2002 00:00:00 GMT; path=/cgi-bin; domain=helloworld.pl;

    Don't put a slash at the end of the path, Lynx says it's incorrect, and it'll give you a headache if you NEED to correct all the cookies later.