My implementation of Apache::Session::MySQL dies along the way, and gives unclear warning. [error] Died at /usr/lib/perl5/site_perl/5.8.0/Apache/Session/Generate/MD5.pm line 40.
I decided to implement session as a module call Store::Session, so as to minimize recoding it in many script.
############################################################################# # Program: # Author: Babale Fongo # # Date: 01-03-2004 # # Description: Module for database connections. # # Copyright (c) Babale Fongo # # Email: [EMAIL PROTECTED] # # Web: http://www.domain name.com # # ======================================================================= # # # # <<< Technical information >>>> # # # # # ############################################################################# ##################################################### # Beginning of the script. # ##################################################### package Store::Session; use vars qw(@ISA @EXPORT); use Exporter; @ISA = qw(Exporter); @EXPORT = qw(new getId closeSession deleteObject); use strict; use Apache::Session::MySQL; ############################################# # Start a new session ############################################## sub new { my ($dbh, $session_id) = @_; my %session; tie %session, "Apache::Session::MySQL", $session_id,{ Handle => $dbh, LockHandle => $dbh }; return;#(\%session); } 1;
#!/usr/bin/perl -w ############################################################################# # Program: # Author: Babale Fongo # Date: # Description: # Copyright (c) Babale Fongo # Email: [EMAIL PROTECTED] # Web: http://www.domain name.com # ======================================================================= # # <<< Technical information >>>> # # ############################################################################ use strict; use lib qw(/data/www/perl-bin/jupiterShop/Modules); use Store::Session; use CGI qw(:all); use DBConnect; use Layout; # Database connectivity my $dbh = dbConnect(); # Get value of url or cookie id if any. my $session_id = cookie("session"); #|| param("session"); my ($cookie, $session_ref); if (defined($session_id)){ $session_ref = Store::Session->new($dbh, $session_id); defined($session_ref) || die ("Couldn't retrieve session: Apache::Session::errstr"); }else { $session_ref = Store::Session->new($dbh, undef); defined($session_ref) || die ("Couldn't start a new session: Apache::Session::errstr"); $cookie = cookie(-name => "session", -value => $session_ref, -expires => "+3d", -domain => ".shop.com" ); } print header (-cookie => $cookie); print header(); start_html(); print p ("The session id is : $session_ref"); end_html();
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>