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!


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to CGI::Session losing set params by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.