in reply to Re^2: CGI::Session keeps re-using same session ID
in thread CGI::Session keeps re-using same session ID
I'm astonished at how difficult sessions are to get working, even for an experienced Perl programmer like me.
I'm not :) HTTP is complicated enough, and then you have to deal with implementation details of CGI.pm and CGI::Sessions.pm
CGI::Session->new will try to load a session first, and only create a new session if it fails to load one
The thing is, since in CGI protocol, cookies are retrieved via $ENV{HTTP_COOKIES}, if there is a cookie set, CGI::Session will always load an existing session, because CGI.pm (or CGI::Cookies.pm) will always read $ENV{HTTP_COOKIES}
Hopefully you have read Basic cookie management (May 01) by now,
but here is how you fix your program without changing the program flow,
you delete the session if you can load it, then you create a new one
if ($action eq 'login') { $session = CGI::Session->load( "driver:File", undef, $dsn_args ); eval { $session->delete; $session->flush; }; $session = CGI::Session->new( "driver:File", undef, $dsn_args ) or die CGI::Session->errstr; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: CGI::Session keeps re-using same session ID
by alain_desilets (Beadle) on May 04, 2012 at 18:42 UTC | |
by Anonymous Monk on May 04, 2012 at 20:30 UTC |