Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

How can I maintain a session cookie?

by yschang (Initiate)
on Feb 02, 2000 at 21:46 UTC ( #2746=perlquestion: print w/replies, xml ) Need Help??

yschang has asked for the wisdom of the Perl Monks concerning the following question: (cgi programming)

I would like maintain a session cookie to track users on my site, but the session cookie should be destoryed once the user closes all copies of their browser. How can do it?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How can I maintain a session cookie
by Anonymous Monk on Feb 05, 2000 at 09:32 UTC
    First of all use the CGI module, it'll make your life easier in general, not just dealing with cookies.
    use strict; use CGI qw(:standard); $q = new CGI; # Create a 11 character random string as a # session id. (Yes, it's swiped from the perl cookbook:-) @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9 ); $usersession = join("", @chars[ map { rand @chars } (1 .. 11) ]); # Set a cookie that expires when # the user closes their browser $initcookie = $q->cookie( -name=>'User_Session', -value=>$usersession, -expires=>'', # leave this blank -path=>'/', -domain=>'', -secure=>0 ); print $q->header(-cookie=>$initcookie);
    For more info on the CGI module, go to: Shawn
Re: How can I maintain a session cookie
by turnstep (Parson) on Mar 25, 2000 at 00:57 UTC
    Basically, any cookie that has NO expiration date, or an expiration date in the past (according to the user's system) will not be stored in the cookie.txt (or equivalent) file on the hard drive when the browser exits.
Re: How can I maintain a session cookie?
by lindex (Friar) on Jul 19, 2000 at 03:38 UTC

    Re: How can I maintain a session cookie?

    Originally posted as a Categorized Answer.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2023-10-01 21:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found