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?

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

In reply to Value for session set in CGI::Session is undef 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.