bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
I'm able to write the session, I see the cookie, but on the return trip to my index.cgi, while it reads the cookie and session id, the session params are coming up empty. I've tried it everyway but Tuesday--I might not be understanding the documentation or how CGI::Session should be set up. Here's my flow:
User submits password | valid? | +----Y----+-----N----+ | | write new login CGI::Session screen and cookie | next TMPL screen output | user selects different page | back to index.cgi | check for session | +---Y---+-----N----+ | | write new login CGI::Session screen and cookie | sessionid ok but params gone! | new TMPL page output
Here's some simplified code:
sub set_session { my $session = new CGI::Session("driver:File", $query, {Directory=>' +/tmp'}); $session->param('user_name', $user_name); $session->param('user_id', $user_id); $session->param('logged-in',1); $session->expires("+15m"); my $cookie = $query->cookie(CGISESSID => $session->id ); print $query->header(-cookie => $cookie); } sub get_session { my $session_id = cookie('CGISESSID'); my $session = new CGI::Session("driver:File", $session_id, {Directo +ry=>'/tmp'}); if ( !$session->param('logged-in') ) { show_login(); } else { $user_name = $session->param('$user_name'); $user_id = $session->param('$user_id'); } }
I had it working in my example where I had two different scripts, one setting the session and the other getting it. In this example, I have the one script doing both--don't know if that makes any difference. Thanks all!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Session losing set params
by jgallagher (Pilgrim) on Dec 01, 2005 at 16:49 UTC | |
by bradcathey (Prior) on Dec 01, 2005 at 21:35 UTC |