[cgiapp] Changing CGI::Session name within a CGI::Application
Mark Knoop
mark at rawcane.net
Wed Feb 6 09:19:36 EST 2008
> Hi
>
> I am trying to use the CGI::Application::Plugin::Session but I am getting
> a bit confused with what objects are what.
> ...
Ok. I have made some progress in pinnign this down and it seems I have a
problem with the session object.
This code recreates the scenario.
package GSystem::Test;
use base 'CGI::Application';
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Application::Plugin::Session;
sub cgiapp_init {
my $self = shift;
my $session_path;
CGI::Session->name('lsid');
$self->session_config(
CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {
Dir=>'D:\sessions\\' } ], # running on windows/IIS
DEFAULT_EXPIRY => '+5m',
SEND_COOKIE => 0,
);
}
sub setup {
my $self = shift;
$self->start_mode('no_lsid');
$self->run_modes(
'got_lsid' => 'got_lsid',
'no_lsid' => 'no_lsid'
);
}
sub cgiapp_prerun {
my $self = shift;
my $session = $self->session;
if ($self->query->param('lsid') ) {
$self->prerun_mode('got_lsid');
} else {
$self->session->param('rsid', 'SOME_VALUE');
$self->prerun_mode('no_lsid');
}
}
sub got_lsid {
my $self = shift;
my $lsid = $self->session->id;
my $rsid = $self->session->param('rsid');
my $output = <<EOF;
<html><body>Got lsid $lsid - rsid is $rsid</body></html>
EOF
return $output;
}
sub no_lsid {
my $self = shift;
my $lsid = $self->session->id;
my $output = <<EOF;
<html><body>New lsid is $lsid - <a href =
"http://my.url.com/test.pl?lsid=$lsid">Link</a></body></html>
EOF
return $output;
}
1;
If I call this with no parameters it returns a link with the new session id
as a value to lsid. If I click on this then it runs the got_lsid run mode
but has not successfully retrieved the rsid value from the session data and
has created a new session id.
Any ideas on how to pin this down? I'm sure I am doing something dumb...
Cheers
Mark
More information about the cgiapp
mailing list