I'm new to perl, and am having the worst trouble loading my session data. I have two very short, very basic scripts to test the functionality.
script1.pl use CGI; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session ( '-ip_match' ); my $session = CGI::Session->new(); $session->param("TestName", "TestValue"); $session->flush(); print $session->header(-location=>'test.pl'); script2.pl use CGI; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session ( '-ip_match' ); my $session = CGI::Session->load() or die CGI::Session->errstr(); print $session->id . " - " . $session->param('TestName');

After script1.pl executes, I see the cookie in my browser with the CGISESSID parameter and the session ID as the value.

Looking at network traces, I see the "Cookie: CGISESSID=e3b27743bdd22a2d446abb1f9454a721\r\n" begin passed in the header data.

On the server I see the "cgisess_e3b27743bdd22a2d446abb1f9454a721" session file created in the system temp directory. Opening the session file on the server with notepad shows the (TestName and TestValue)'s are stored in the session file.

But when script2.pl tries to load the session, I get nothing. No session ID, no parameters. The result script2.pl that is displayed in the browser is a hyphen ( - ), due to print being fed the " - " string literal.

I've even tried changing CGI::Session->load() in script2.pl to CGI::Session->new(), however, this only results in returning a brand new session. Opening the new session file from the temp directory shows the "TestName" and "TestValue" do not exist.

Seeking enlightenment.


In reply to Loading a session from CGI::Session by SitrucHtims

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.