No confusion :) Please allow me to explain:
When I first wrote programs that used CGI::Session, I made the same mistake that I describe. . . I accidentally created a new session every time my program ran. Or, to look at it another way, every time the browser made a request of my script on the webserver, a new session was created. Once I realized what I had done, it was an easy thing to fix.
What I do struggle to understand is why his script appeared to work on Apache but not on iServer. As I never intend on using iServer I don't care all that much either ;) Whether or not it's some sort of bad coincidence or conclusion, or whether its a program bug or configuration issue is impossible to tell unless we get some code though ;) (and at this point I'm doubting that will ever surface).
Happy weekend!
MrCromeDome | [reply] |
"(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=>'/')
);
}
}
| [reply] |
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 | [reply] [d/l] |
The server has Apache Web server and Netscape iPlanet installed and apparently each Web server's cgi-bin directory is mapped to the same subdirectory. So in order to run a perl CGI script under each Web server, you need to use a (slightly) different URL.
The code is writing session data as files in a certain subdirectory on the server. When using the URL for Apache Web server, you get only 1 session file created for you and this file increases in size (i.e., the report data is appended to your existing session file) when you run a report which allows you to display the details of a specific record listed on the report.
But when using the URL for Netscape iPlanet, you get a new session file created when you run the report and again when you try to display the details of a specific record. | [reply] |