I have a simple program which uses apache session and cookies... Now my problem is that when I go to the program via domain.com/cgi-bin/prog.pl, it does not seem to be able to tie the session hash to the id found in the cookie.

But running the same program from directory level 132.345.45.46/directory1/cgi-bin/prog.pl it is able to tie the session hash to the id found and then add to it as expected...

What seems to happen is that it gets an id from the cookie, and then it succeeds in the eval block, but when it exits from the eval block the $id is defined as undef...

Anybody got any suggestions...
$id = $query->cookie(-name=>"SESSID"); eval { tie %session, 'Apache::Session::File', $id, { Directory => "$cartInfoPath", LockDirectory => "$cartInfoPath"}; }; if ($@) { if ($@ =~ /^Object does not exist in the data store/) { $id = undef; tie %session, 'Apache::Session::File', $id, { Directory => "$cartInfoPath", LockDirectory => "$cartInfoPath"}; } } if ($id == undef) { $cookie = $query->cookie( -name=>'SESSID', -value=>$session{_session_id}, -expires=>'+1y', -path=>'/'); print $query->header(-cookie=>$cookie); print "Assigned session ID ".$session{_session_id}."<br>\n"; } else { print $query->header(); print "Not assigned session ID already ".$session{_session_id}." < +br>n"; }

Edit by dws to fix formatting and add <code> tags


In reply to Apache Session problem by Anonymous Monk

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.