Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: having problems w/CGI-Session

by aroc725 (Acolyte)
on May 24, 2005 at 13:08 UTC ( [id://459937]=note: print w/replies, xml ) Need Help??


in reply to Re^3: having problems w/CGI-Session
in thread having problems w/CGI-Session

"(and at this point I'm doubting that will ever surface)."

Oh, ye of little faith. :-P

Here's the code for the 'initialize_session' method that's called from the 'cgiapp_init' method of the 'Base.pm' module that's inherited from 'CGI::Application':

sub initialize_session
{
my $self = shift;
my $q = $self->query();


my $session = CGI::Session->new('driver:File',
$q->cookie('CGISESSID') || $q->param('CGISESSID') || undef,
{ Directory=>'/ctrlacc/lhdsurv/session/mid_yr_rpt_survey' } )
or die($CGI::Session::errstr);


# 05-17-2005: See if following code works
# expire the session itself after 1 idle hour
$session->expire('+1h');


#Initialize the session and get the id.
my $sessionid = $session->id();
$self->param('sessionid'=>$sessionid);
$self->param('session'=>$session);


if ( (! defined($q->cookie('CGISESSID'))) or
($sessionid ne $q->cookie('CGISESSID')) )
{
# If the session has expired, reset the cookie
$self->header_add(-cookie => $q->cookie(-name => 'CGISESSID', value => $sessionid, -path=>'/') );
}
}

Replies are listed 'Best First'.
Re^5: having problems w/CGI-Session
by MrCromeDome (Deacon) on May 25, 2005 at 02:44 UTC
    Thank you, I like being mistaken in that way :)

    You might want to consider using CGI::Application::Plugin::Session. All that code you have could be boiled down to the following:
    use CGI::Application::Plugin::Session; my %options = ( Directory => "/ctrlacc/lhdsurv/session/mid_yr_rpt_survey" ); $self->session_config( CGI_SESSION_OPTIONS => [ undef, $self->query, \%options ], SEND_COOKIE => 1, );
    and it would be more readable. I typically throw that in the cgiapp_init() method of my CGI::Application base class, but if you wanted to throw it in it's own function it's probably alright.

    And I've never had any luck setting expiration times with CGI::Session. They never work for me. Either don't expire the cookie, or set it to expire as soon as the browser closes.

    Good luck, I hope this helps!
    MrCromeDome

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found