fasa77 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have a problem which I thought you could help me with:
I create a CGI:Session object. After that, I try to call again to the CGI::Session->new with the session id I get from the first call.
In Linux I get a success in both calls.
But in SUN, the second call does not return me anything.
Do you have an idea what might be wrong?
Here's the code:
#!/usr/bin/perl use CGI qw(:standard); use CGI::Session; my $tmp_directory = '/tmp'; my $session_id = CGI->cookie("CGISESSID") || CGI->param('CGISESSID') +|| undef; if (not $session_id){ my $first_session = new CGI::Session(undef, undef, {Directory=>$tmp +_directory}); print "first session = $first_session\n";## VALID SESSION $session_id = $first_session->id; } my $second_session = new CGI::Session(undef, $session_id, {Directory + => $tmp_directory}); print "second session = $second_session\n"; ## NOTHING!

Thanks,
fasa

Replies are listed 'Best First'.
Re: CGI::Session in SUN OS
by Corion (Patriarch) on Jul 21, 2010 at 13:29 UTC

    If it works in one place and does not in the other, find out the differences. One or more of the differences likely is responsible for what you see.

    Have you compared the module versions?

    Is /tmp writable by the webserver user?

    Does eliminating CGI and running the script from the command line change anything?

      I tried it with several directories beside /tmp and it fails in all fo them.
      It writes only the first session.
      The CGI::Session version which fails is 4.2
        Why aren't you error checking?
        CGI::Session..... or die CGI::Session->errstr();
Re: CGI::Session in SUN OS
by sierpinski (Chaplain) on Jul 21, 2010 at 14:06 UTC
    Compare the differences in Linux and Solaris of the ENV environment variables.

    Also, instead of new CGI::Session try CGI::Session->new. It *used* to be the same (and in most cases still is) but I've seen different behaviors among different platforms before. Not sure that is your problem, but it's a simple thing to check. I've also heard (Monks -- please correct me if I'm wrong) that it's just better programming practice because its considered "better OOP" to use the ->new method instead of using the new keyword... (Hopefully I worded that correctly)
      Thanks for you suggestion.
      I changed it to CGI::Session->new but still get the same error:
      new(): failed: load(): couldn't retrieve data: retrieve(): couldn't lock '/tmp/cgisess_9635d822f1e213041b1bf81cd124bbb9': Bad file number at cgi_test.pl line 14.