Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

How can I maintain a session cookie?

by yschang (Initiate)
on Feb 02, 2000 at 21:46 UTC ( [id://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=>'www.somewebsite.com', -secure=>0 ); print $q->header(-cookie=>$initcookie);
    For more info on the CGI module, go to: http://stein.cshl.org/~lstein/ 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-19 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found