Fellow Monasterians,

Note: I posted a similar question the other day, but have simplified it somewhat.

Anyway, I'm on a mission to understand CGI::Sessions but I'm missing something.

My guess is that I'm not not using new CGI::Session() properly. Here is a reduction of a much larger application. I hope someone can spot the issue here, without lots of extraneous code.

Problem: it looks like I'm setting a new session and losing my value: logged-in. Obviously, I'd like to keep the session the same, and the value.

my ($logged_in, $session_id) = write_session(); # Dumper to file shows # $VAR1 = 1; # $VAR2 = 'ae83ec8591d8579c1955d3e798dde74b'; my ($logged_in, $session_id) = check_session(); # Dumper to file shows # $VAR1 = undef; # $VAR2 = '1209a2de95b31a59d338f70458702860'; sub write_session { my $session = new CGI::Session(); print $session->header(); $session->param('logged_in' => 1); $session->expire('+2h'); return ( $session->param('logged_in'), $session->id() ); } sub check_session { my $session = new CGI::Session(); return ( $session->param('logged_in'), $session->id() ); }

Thanks in advance.

—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 appears to be overwriting itself 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.