seven.reeds has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I am trying to use CGI::Session 4.42 on a Redhat Enterprise system running Apache 2. I also have the default redhat MySQL build for my redhat version.
I am just starting out with CHI::Session and I must be doing something wrong... but I can not figure it out.
I have tried to use ideas from the CGI::Session tutorial and I have the following for a login function:
NOTES: "$dbh" is an active database handle. It is defined and
created elsewhere in the code.
"$CGI" is an active CGI.pm
instance. It is defined and created elsewhere in the code.
"$CONFIG" is a hash that holds configuration info that is pulled in
from an external onfig file.
The following executes without error but no records are stored in the database. A sessionID is acquired from CGI::Session and a cookie is created that looks correct but, again, no session data is stored in the "sessions" table.
All ideas are welcome. I am probably not doing something fundamental.
sub login { my ($dbh) = @_; my ($email) = $dbh->quote($CGI->param('email') || undef); my ($password) = $dbh->quote($CGI->param('password') || undef); my ($loginSessionID) = $CGI->param('loginSessionID') || undef; eval { # # email should be an RFC compliant email address. # my $tmp = <<EOF; SELECT id FROM users WHERE LOWER(email) = LOWER($email) AND password = $password EOF my $sth = &return_query($dbh, $tmp); my @row = $sth->fetchrow_array; $result{userID} = undef; if (@row) { $result{userID} = $row[0]; CGI::Session->name( $CONFIG->{userSession}{cookies}{LOGIN}{name} || "CGISESSID"); $SESSION = CGI::Session->load("driver:MySQL", $CGI || $loginSessionID, { DataSource => join(':', $CONFIG->{mysql}{DSN}, $CONFIG->{mysql}{Collection}), TableName => 'sessions', IdColName => 'id', DataColName => 'data', Handle => $dbh, }) || die CGI::Session->errstr() . "\n"; if ($SESSION->is_expired) { # # If we are picking up an old session see if it is # already expired. If it is expired delete it from # the store and flush the session data. # $SESSION->delete(); $SESSION->flush(); } if ($SESSION->is_empty) { # # This "new" is CGI::Session magic. THe session # definition in the "load" above is remembered and # will be re-applied here. # $SESSION = CGI::Session->new(); } $result{loginSessionID} = $SESSION->id(); $SESSION->param('userID', $result{userID}); $SESSION->expire( $CONFIG->{userSession}{cookies}{LOGIN}{expire} | +| "+30m"); $COOKIES{loginSession} = $CGI->cookie( -name => $CONFIG->{userSession}{cookies}{LOGIN}{nam +e}, -value => $SESSION->id(), -expires => $CONFIG->{userSession}{cookies}{LOGIN}{expire} | +| "+30m", -path => $CONFIG->{userSession}{cookies}{LOGIN}{pat +h} || "/", -domain => $CONFIG->{userSession}{cookies}{LOGIN}{domain} | +| "", -secure => $CONFIG->{userSession}{cookies}{LOGIN}{secure} | +| 0, ); $SESSION->flush(); } }; if ($@) { push(@{ $result{error} }, $@); } return encode_json(\%result); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Session not "storing" anything
by Khen1950fx (Canon) on Dec 02, 2010 at 00:30 UTC | |
|
Re: CGI::Session not "storing" anything
by afoken (Chancellor) on Dec 02, 2010 at 15:25 UTC | |
by Anonymous Monk on Dec 02, 2010 at 18:26 UTC | |
by afoken (Chancellor) on Dec 04, 2010 at 09:00 UTC |