I'm trying to get a simple first CGI::Application::Plugin::Session program going to understand how cookies/sessions etc work. I'm developing on XP with a local install of Apache 2.2, the latest version of ActiveState perl and versions of CGI::Session, CGI::Application and CGI::Application::Plugin::Session installed via ActiveState's package manager.
I've written a stripped down version of my program that illustrates the problem I'm having:
cookieprob.pm:
package cookieprob; use strict; use base 'CGI::Application'; use HTML::Template; use CGI::Application::Plugin::Session; sub setup { my $self=shift; $self->start_mode('add'); $self->run_modes('add' => 'add_mode'); $self->tmpl_path('../tmpl');#('/.'); } sub cgiapp_init { my $self = shift; # Configure the session $self->session_config( CGI_SESSION_OPTIONS => [ "driver:file", $self->query, {Dire +ctory=>'../tmp'}], DEFAULT_EXPIRY => '+1w', COOKIE_PARAMS => { -expires => '+1h', -path => '../tmp', }, SEND_COOKIE => 1 ); } sub add_mode { my $self = shift; my $qry = $self->query(); my $messageOut; # Load the template my $template = $self->load_tmpl('add.tmpl.html'); my $remember = $qry->param("remember"); if(!$remember) { $template->param(debugmessage => "No 'remember' parameter"); return $template->output; } $template->param(asin => $remember); my $session = $self->session; my @vals; if($session->param("values")) { @vals = split(/,/, $session->param("values")); } push(@vals, $remember); # add new value to list of vals. my $valueList = join(",", @vals); $session->param("values", $valueList); $messageOut = $valueList; #$template->param("debugmessage" => $valueList); #my $temp; # Retrieve session info and stick on scr +een foreach my $key (keys(%{$session->dataref()})) { $messageOut=$messageOut."<p>$key = ".$session->param($key); } $template->param(debugmessage => $messageOut); # return the template output return $template->output; } 1;
and cookieprob.pl:
#!c:/perl/bin/perl.exe -w use strict; use cookieprob; my $cookieprobApp=cookieprob->new(); $cookieprobApp->run();
Incidentally, I have a template 'add.tmpl.html' with two template fields - debugmessage and asin. For brevity's sake I haven't included that here.
At the moment I just enter the following url into my browser's address bar:
http://localhost:8080/cgi-bin/cookieprob.pl?remember=tom
then try viewing
http://localhost:8080/cgi-bin/cookieprob.pl?remember=mary
Now, what I expect (intend) to happen is that when I view the second url I should see "Tom,Mary" as the value of 'values'. In fact it's just "Mary". When I look at my browser's cookie list I can see cookies issued by localhost, and when I look in /Apache2.2/tmp I can see a list of files with names like cgisess_ec5c439523af2247814273d7c163921f with modified times that correspond with the times at which I viewed the above urls, and with _SESSION_IDs that match those displayed when I view the above pages. What I would guess I should expect is to see one session ID, not different IDs each time I view the page. It seems to me that ...Plugin::Session is creating a new cookie/session each time I view the page rather than retrieving the cookie from the browser.
I'm sorry if that's not a very coherent explanation of the problem, but hopefully you get the idea.
Any suggestions are gratefully received. If I've omitted some piece of relevant information please let me know and I will supply it.
Thanks very much,
Luke
In reply to Problems with CGI::Application::Plugin::Session by lsteele
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |