Greetings Monks,

I'm having trouble with CGI::Session and I can't figure out what's going on. I've tried everything, POD, man pages, google, to no avail. Anyway, I know someone here will be able to point me in the right direction.

I'm using CGI::Session for session tracking. I'm creating the session, populating session parameters, and writing the CGISESSID cookie in a login script. I'm then redirecting to a page generation script. In the page generation script, I'm reading the cookie to get the session ID and then creating a new session based on the stored session id. (I'm also passing the SID of the first session in the query string for troubleshooting.) According to the documentation (tutorial, cookbook, perldoc, etc.) , this should be creating a session object associated with the established session ID instead of creating a new session. The code I'm using is as follows:

# -----8<----- my $cgi = new CGI(); my $cookieval = $cgi->cookie("CGISESSID"); my $paramval = $cgi->param("CGISESSID"); my $sid = $cgi->cookie("CGISESSID") || $cgi->param("CGISESSID"); my $session = new CGI::Session(undef, $sid, {Directory=>File::Spec +->tmpdir()}); my $sid2 = $session->id(); # -----8<-----

In this scenario, $cookieval = $paramval = $sid. These all retrieve the same session ID. However, once I create the session variable, I expect $sid2 to be the same as the previous three variables. It is not. Declaring 'my $session...' creates a brand new session object, despite the fact that I'm giving it the SID of the previous session. Once this happens, I can't access any of my previously written session parameters because $session is now associated with the new session object. I'm certain I'm doing something wrong, but I can't gure it out.

My apologies for troubling you with this and many thanks in advance for your assistance.

Thanks again,

Larry


In reply to Problem with CGI::Session module -- Getting a new session every time by larryp

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.