Hi guys, I've been trying to write simple login/logout scripts with CGI::Sessions but I'm not having much luck. So everything compiles and runs ok (using strict etc) but not quite as I expected. Here is my sample code:
sub loadSession($$){ my ($dbhandle,$cgi) = @_; my $session = CGI::Session->load("driver:MySQL", $cgi, {Handle=>$d +bhandle}); if ( $session->is_expired && $session->param("logged_in")) { displayLoginPage("Your session has expired, please log in agai +n"); exit(0); }elsif ( $session->is_empty) { $session = $session->new("driver:MySQL", $cgi, {Handle=>$dbhan +dle}); $session->expire('+1m'); print $session->header(); displayLoginPage(undef); exit(0); }else{ print $session->header(); } return $session; } sub logout($$){ my($cgi,$dbhandler) = @_; my $session = CGI::Session->load("driver:MySQL", $cgi, {Handle=>$d +bhandler}) or die CGI::Session->errstr; $session->clear(); $session->delete(); }
So the session expires but isn't marked as expired. As in the elsif branch for the empty session is executed not the expired branch. Also when I attempt to logout of the session the session id still seems to be valid. A new session id is not generated (I print them out on each page) for the login page. Can anyone point out the flaws in my logic? I've been through the cpan tutorial but I still amn't getting this.

In reply to Problems with CGI Sessions by nemo

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.