dariusj has asked for the wisdom of the Perl Monks concerning the following question:
I'm following this tutorial on cpan - this is how I'm initialising the session:
After that I have an if-else clause, with the cgi acting accordingly to what the user clicked on:$session = new CGI::Session(undef, undef, {Directory=>'./tmp'}) or die + CGI::Session->errstr;
The sign_in method returns 0 if authentication was unsuccessful, and a cookie otherwise and creates a sign_out button.my $action = $cgi->param("submit"); if($action eq "Sign in") { #If user signing in $cookie = $tools->sign_in($cgi,$dbh,$session); if($cookie eq "0") { #Login failed print $cgi->header; print $cgi->start_html(-title=>"Home Page"); print "Login failed"; $session->delete; $logged = 0; } else { #Login successful print $cgi->header(-cookie=>$cookie); print $cgi->start_html(-title=>"Home Page"); print "Welcome ".$session->param("user_name"); print $cgi->start_multipart_form(-method=>'post', -action=>'main.pl', -name=>'sign_out'); print $cgi->submit(-name=>'submit',-value=>'Sign out'); print $cgi->end_form; $session->expire('+30m'); $logged = 1; } } else { print $cgi->header; print $cgi->start_html(-title=>"Home Page"); }
The session expires in 30 mins and is present in the file is present in the right directory.
Once the user is signed in, he can select a radio button and open another page - here I always get an empty session!
This is the next page's session initialisation, and is pretty much straight from the tutorial:
It always goes to the is_empty clause. Any idea what I'm doing wrong?my $session = CGI::Session->load or die CGI::Session->errstr; print $session->header; if ($session->is_expired) { print $session->header, $cgi->start_html, $cgi->p("Your session timed out. Click here to start a new sessio +n."), $cgi->end_html; exit(0); } if($session->is_empty) { print $cgi->start_html; print "Click here to sign in"; print $cgi->end_html; exit(0); }
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl CGI::Sessions
by vc_will_do (Sexton) on Aug 31, 2007 at 03:39 UTC | |
by dariusj (Sexton) on Sep 07, 2007 at 13:24 UTC | |
|
Re: Perl CGI::Sessions
by deMize (Monk) on Jun 25, 2010 at 00:32 UTC | |
by Anonymous Monk on Nov 05, 2015 at 20:34 UTC | |
by Anonymous Monk on Jun 25, 2010 at 01:44 UTC | |
by deMize (Monk) on Jun 25, 2010 at 14:53 UTC | |
by Anonymous Monk on Jun 25, 2010 at 14:55 UTC | |
|
Re: Perl CGI::Sessions
by deMize (Monk) on Jun 25, 2010 at 14:47 UTC | |
by deMize (Monk) on Jun 25, 2010 at 14:51 UTC |