Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


I have been working on an old Perl login script, to make a couple of improvements. I have ran into a couple of problems with CGI::Session.

Upon login, if I use a header redirect to the homepage (a html webpage), then click on the "members zone" link, it will tell me that i'm not logged in. If I then re-click the same link, it will display what I expect, the "members zone" (logged in). This problem does not occur if I header redirect to the "members zone" directly after logging in. Another, I think related issue, the "Members Zone" is located "". I also have the directory "" which contains an index.php file that redirects to "". It will also tell me that i'm not logged in, no matter what i try.

These issues seem to be related to the cache, and that its using the same compiled output of the "members zone" from before logging in. However, upon clearing my cache, then testing, the problem still occured. Why is this problem occurring, and how can I resolve it?

Here are the relevant sections of my code:


my $session = new CGI::Session(); if ($data{'Param'}{'Referer'}) { $session->param(-name => 'Referer', -value => $data{'Param'}{'Refe +rer'}); } my $referer = $session->param(-name=>'Referer') || $default_referer; # if ($data{'Param'}{'Login'}) { my $statement = "SELECT Client, Email, First_Name, Telephone_Numbe +r FROM $dbtable_Users WHERE (Email='$data{'Param'}{'Email'}' AND Pass +word='$data{'Param'}{'Password'}')"; my $sth = $dbh->prepare($statement); $sth->execute(); if ($sth->rows == 0) { $data{'Login'}{'Fail'} .= 'Wrong email / password combination. + Please retry. If you are having problems logging in, <a href="Contac +t-Us.php">Contact Us</a>. '; } else { while (my @row = $sth->fetchrow_array()) { $data{'Session'} = { 'LoginEpoch' => time, 'Client' => $row[0], 'Email' => $row[1], 'FirstName' => $row[2] }; } $session->param(-name => 'LoggedIn', -value => $data{'Session' +}); $session->expire('LoggedIn', "+10000s"); $session->flush(); print redirect($referer); exit(1); } } elsif ($data{'Param'}{'Logout'}) { $session->clear(['LoggedIn']); $session->flush(); print redirect(' have logg +ed out'); exit(1); } else { $data{'Login'}{'Begin'} .= q(Please login. If you are having probl +ems logging in, <a href="Contact-Us.php">Contact Us</a>. ); } print $session->header(); #etc

Members Zone:

my $session_data; my $session = load CGI::Session(); if ($session->param(-name=>'LoggedIn')) { $session->expire('LoggedIn', "+10000s"); $session_data = $session->param(-name=>'LoggedIn'); } $session->flush(); #Not logged in unless ($session_data) { print redirect(' must be l +ogged in to view this page&Referer=') +; exit(1); } #Begin logged in if ($session_data) { print $session->header(); #etc }



In reply to CGI::Session "cache" issue by Zhris

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2017-08-18 11:57 GMT
    Find Nodes?
      Voting Booth?
      Who is your favorite scientist and why?

      Results (300 votes). Check out past polls.