SketchySteve has asked for the wisdom of the Perl Monks concerning the following question:
Page one... use CGI::Session; use CGI; my $cgi = new CGI; my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'}); $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie); $session->param('f_name', 'Sherzod'); print '<a href="session2.pl">Page 2</a>';
Page 2... use strict; use CGI::Session; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI; my $cgi = new CGI; my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'}); my $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie); my $name = $session->param("l_name"); print $name; I found one example on the web which isnt working and comes up with "Y +ou have not logged in". Page one... use CGI; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session ( '-ip_match' ); $q = new CGI; $usr = $q->param('usr'); $pwd = $q->param('pwd'); if($usr ne '') { # process the form if($usr eq "demo" and $pwd eq "demo") { $session = new CGI::Session(); print $session->header(-location=>'index.pl'); } else { print $q->header(-type=>"text/html",-location=>"login.pl"); } } elsif($q->param('action') eq 'logout') { $session = CGI::Session->load() or die CGI::Session->errstr; $session->delete(); print $session->header(-location=>'login.pl'); } else { print $q->header; print <<HTML <form method="post"> Username: <input type="text" name="usr"> Password: <input type="password" name="pwd"> <input type="submit"> </form> HTML }
use CGI; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session ( '-ip_match' ); $session = CGI::Session->load(); $q = new CGI; if($session->is_expired) { print $q->header(-cache_control=>"no-cache, no-store, must-revalid +ate"); print "Your has session expired. Please login again."; print "<br/><a href='login.pl>Login</a>"; } elsif($session->is_empty) { print $q->header(-cache_control=>"no-cache, no-store, must-revalid +ate"); print "You have not logged in"; } else { print $q->header(-cache_control=>"no-cache, no-store, must-revalid +ate"); print "<h2>Welcome"; print "<a href='login.pl?action=logout'>Logout"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Storing Session Across Pages - IIS To Blame?
by perrin (Chancellor) on Apr 17, 2007 at 15:03 UTC | |
|