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?
In reply to Value for session set in CGI::Session is undef by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |