bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
I've posted several questions about CGI::Session over the past months, but they have all been different issues. Here's a new one that I've distilled it down to the code below.
Question: Why is the value of a param not get past the subroutine that sets it?
my $logged_in = write_session( $user ); print Dumper($logged_in, $session->param('user')); sub write_session { my $user = shift; my $session = new CGI::Session(); $session->param('user' => $user); $session->param('logged_in' => 1); my $cookie = $query->cookie( CGISESSID => $session->id ); #print $query->header(-cookie => $cookie); print $session->header(-cookie => $cookie); #$session->flush() return ($session->param('logged_in')); } ---------- DUMPER ------------ $VAR1 = 1; $VAR2 = undef;
You can see that I test for the successful setting of the param in the routine, but it returns undef when I am back in the calling module. Note: the cookie is set and a session id generated. A cat of the actual session file in /tmp shows everything is there before I try to read it. And you can see I tried flush() and setting the cookie directly, all to no avail.
I use CGI::Application::Plugin::Session in newer projects, which has lazy loading (not initiated until called), but this doesn't seem to be the same deal). I've read the lovely CGI::Session::Tutorial several times, but no approach seems to work. Thoughts?
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Value for session set in CGI::Session is undef
by moritz (Cardinal) on Apr 07, 2009 at 19:14 UTC | |
Re: Value for session set in CGI::Session is undef
by lostjimmy (Chaplain) on Apr 07, 2009 at 19:16 UTC | |
Re: Value for session set in CGI::Session is undef
by VinsWorldcom (Prior) on Apr 07, 2009 at 19:51 UTC | |
by bradcathey (Prior) on Apr 07, 2009 at 21:32 UTC |