Upland has asked for the wisdom of the Perl Monks concerning the following question:
I have some code that has been working fine - until I moved the session initialisation into one of my modules. Now the cookie is no longer being set via print->header - and so a new session is created every time I run it. Here's the (heavily pruned/edited) code:
# login.pl use CGI; use CGI::Session ( '-ip_match' ); use DBI; use MyPM qw(&open_db &close_db &getSession); use strict; use warnings; my $cgi = new CGI; my $dbh = open_db; my $session = getSession($cgi, $dbh); # Call to MyPM.pm close_db($dbh); ...... code ...... print $session->header(-type => 'application/json'); print $json; ======================================= # MyPM.pm use CGI::Session ( '-ip_match' ); our @ISA = qw(Exporter); our @EXPORT_OK = qw( open_db close_db getSession ); sub getSession { my $cgi = shift; my $dbh = shift; my $CGICOOKIE = $cgi->cookie('CGISESSID') || 'x'; my $lng = length($CGICOOKIE); if ( $lng != 32 ) print redirect( -URL => $home ); my $session = CGI::Session->new('driver:MySQL', $cgi, {Handle=>$dbh} +) ; return $session; }
If I change the call to getSession back into this:
my $session = CGI::Session->new('driver:MySQL', $cgi, {Handle=>$dbh});
It works perfectly again and the cookie is set.
Where might I be going wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Session not setting cookie
by kcott (Archbishop) on Mar 11, 2013 at 00:15 UTC | |
by Upland (Initiate) on Mar 11, 2013 at 12:11 UTC | |
|
Re: CGI::Session not setting cookie
by Anonymous Monk on Mar 10, 2013 at 23:49 UTC | |
by Upland (Initiate) on Mar 11, 2013 at 10:56 UTC | |
by Anonymous Monk on Mar 11, 2013 at 20:30 UTC |