in reply to CGI::Session - non-stop session creation problem

I'm confused, but surely your problem is that you've got both CGI::Session and some other code setting cookies which expire at different times?

You say for instance "The problem here is that $sid could exists, even if the sessions has expired but the cookie hasn't (for whatever reason that may happen)" -- why would that happen if you had only one session-management system?

Talk us through it. People log in, and some code sets the "main" cookie. What code does that?



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
  • Comment on Re: CGI::Session - non-stop session creation problem

Replies are listed 'Best First'.
Re^2: CGI::Session - non-stop session creation problem
by Stenyj (Beadle) on Apr 07, 2005 at 01:12 UTC
    my $session = new CGI::Session(undef, $empty, {Directory=>"c:/apac +he/sessions"}); $session->expire('+18h'); $session->param("userID", $userID); my $cookie = $foo->cookie(-name => 'main', -value => $session->id, -expires => '+30d', -path => '/'); print $foo->header(-cookie => $cookie);

    So basically, someone logs in & a cookie is set.

    Then, logged in or not, people visit pages that have the following code:
    my $sid = $foo->cookie('main') || undef; my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/ses +sions'});
    The problem is that, regardless of whether or not the cookie exists, a new session is created.
    The ONLY time I want a session created is in the login script, when the cookie & session should be created.
    AFTER that, I would simply like to grab the session data *IF* one exists.

    Right now, every time a page is loaded, if a session doesn't exists one is created... and then because a cookie isn't stored every time a page is visisted, the next page that's loaded creates a new session because a cookie containing the session data from the previous page wasn't stored. I don't want it to create a new sessions/cookie on every page, only on the login script.

    Any thoughts/suggestions?

    Stenyj