Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

CGI::Session fails to find existing sessions

by hesco (Deacon)
on Aug 17, 2009 at 16:06 UTC ( [id://789211]=perlquestion: print w/replies, xml ) Need Help??

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

My constructor includes this code:

if(!defined($self->{'q'}->param("_SESSION_ID"))){ $self->{'s'} = CGI::Session->new(undef, $self->{'q'}, { Directory => $self->{'cfg'}->param("paths.sessions") } ) +; } else { $self->{'s'} = CGI::Session->new( $self->{'q'}->param("_SESSION_ID +") ); }
However, every attempt to access this application with ?_SESSION_ID=some_session_id in my argument list, seems to result in the creation of a new session object, a new cgisess_some_new_session_id file being created in my /tmp directory.

I would appreciate any clues about what it is I am mising here about how this CGI::Session module is supposed to work

-- Hugh

UPDATE:

This works:

if(!defined($self->{'q'}->param("_SESSION_ID"))){ $self->{'s'} = CGI::Session->new(undef, $self->{'q'}, { Directory => $self->{'cfg'}->param("paths.sessions") } ) +; } else { - $self->{'s'} = CGI::Session->new( $self->{'q'}->param("_SESSION_I +D") ); + $self->{'s'} = CGI::Session->new(undef, + $self->{'q'}->param("_SESSION_ID"), + { Directory => $self->{'cfg'}->param("paths.sessions") } +); }
if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: CGI::Session fails to find existing sessions
by moritz (Cardinal) on Aug 17, 2009 at 16:13 UTC
    If your $self->{'cfg'}->param("paths.sessions") is different from the default (/tmp/), it will try to read the sessions from a different directory as where the previous sessions are stored.

    Also did you check that the previous sessions created files when you stored them?

    Update: since a session ID of undef makes CGI::Session creating a new one, you can omit the condition and simply call something along these lines:

    $self->{'s'} = CGI::Session->new( 'driver:file;serializer:default;id:md5', $self->{'q'}, { Directory => $self->{'cfg'}->param("paths.sessions") +}, );

    (untested)

      Thank you so much Moritz. That was the clue needed. I had not noticed the new session files littering my /tmp/ directory, though I had noticed (but failed to mention) that expected sessions did not seem available in the configured sessions directory. Your clue explains all the known evidence and seems to have resolved the issue. Thanks again.

      -- Hugh

      if( $lal && $lol ) { $life++; }
Re: CGI::Session fails to find existing sessions
by Anonymous Monk on Aug 17, 2009 at 17:38 UTC
    Please hesco, it is small consideration, please stop blaming your tools:)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://789211]
Approved by sweetblood
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found