in reply to Re: Loading a session from CGI::Session
in thread Loading a session from CGI::Session
I tried your code, and it appeared to work, returning
IP_MATCH is turned on Session loaded 209957231a595d0c638d37cda1f4d2a8
but I noticed that the session ID that is printed is not pulled from the loaded session object "$cse", it's pulled from the "$sessionid" variable which was set by the original session. With that in mind, I modified the coded a little. adding
print $cse->id;
to the end.
use strict; use warnings; use CGI; use CGI::Session; my $session = CGI::Session->new(); $session->expire('5m'); $session->param( 'TestName', 'TestValue' ); my $sessionid = $session->id; $ENV{REMOTE_ADDR} = '127.0.0.1'; $session->flush; $session = CGI::Session->new($sessionid); CGI::Session->import qw/-ip_match/; $CGI::Session::IP_MATCH = 1; print "IP_MATCH is turned on\n"; if (my $cse = CGI::Session->load($sessionid)) { print "Session loaded\n"; } else { die CGI::Session->errstr(); } print $sessionid, "\n"; print $cse->id;
The result:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
So it's like the session is still not loading. If I change the code a little more.
use strict; use warnings; use CGI; use CGI::Session; my $session = CGI::Session->new(); $session->expire('5m'); $session->param( 'TestName', 'TestValue' ); my $sessionid = $session->id; $ENV{REMOTE_ADDR} = '127.0.0.1'; $session->flush; $session = CGI::Session->new($sessionid); CGI::Session->import qw/-ip_match/; $CGI::Session::IP_MATCH = 1; print "IP_MATCH is turned on\n"; my $cse = CGI::Session->load($sessionid); if ($cse) { print "Session loaded\n"; } else { die CGI::Session->errstr(); } print $sessionid, " - \n"; print $cse->id, " - \n";
I get a returned Session object, but no session data. Notice I pulled defining the "$cse" variable out of the if statement.
result of the above code is:
IP_MATCH is turned on Session loaded 35d4f016b7aca2f7b3ae032291d2ec74 - -
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Loading a session from CGI::Session
by Anonymous Monk on Apr 17, 2011 at 02:09 UTC | |
by SitrucHtims (Novice) on Apr 17, 2011 at 03:12 UTC | |
by Anonymous Monk on Apr 17, 2011 at 05:58 UTC |