From: Tony V. <av...@co...> - 2002-05-30 07:04:14
|
Hi, I'm a newbie, using Mason on Win32, trying to follow the instructions in "Integrating Apache::Session and Mason". The goal is to store session info in a MySql database, exactly as according to the How-To document, but I can't get past the configuration. Scouring various archives on the web has yielded nothing on this particular problem, though please redirect me if there is a better place to ask... ## This is the error from the apache log: HASH(0x85db30) at C:/Apache/usr/site/lib/Apache/Session/Generate/MD5.pm line 40. ## Here are the relevant lines in MD5.pm ## ...where the new session id is being validated 39: if ($session->{data}->{_session_id} !~ /^[a-fA-F0-9]+$/) { 40: die "$session->{data}->{_session_id}"; 41: } I'm using nothing besides the provided session_handler.pl in the /eg directory (with one line commented out). My httpd.conf is also according to the docs. But I'll include them both in here just in case. httpd.conf ------------- LoadModule perl_module modules/mod_perl.so PerlModule HTML::Mason::ApacheHandler PerlRequire c:/apache/conf/session_handler.pl <Directory "c:/apache/htdocs"> <FilesMatch "*.html"> SetHandler perl-script PerlHandler HTML::Mason </FilesMatch> <FilesMatch "*.comp"> SetHandler perl-script PerlInitHandler Apache::Constants::NOT_FOUND </FilesMatch> </Directory> entire session_handler.pl (i don't dare leave any of it out :-) ------------------ package HTML::Mason; use HTML::Mason::ApacheHandler; use strict; { package HTML::Mason::Commands; use vars qw(%session); use CGI::Cookie; use Apache::DBI; use Apache::Constants; use Apache::Session::MySQL; } my $parser = new HTML::Mason::Parser; my $interp = new HTML::Mason::Interp( parser => $parser, comp_root => 'c:/apache/htdocs', data_dir => 'c:/apache/cgi-bin' ); my $ah = new HTML::Mason::ApacheHandler (interp => $interp); chown(Apache->server->uid, Apache->server->gid, $interp->files_written); sub handler { local *HTML::Mason::Commands::session; my $r = shift; my $database = 'database'; my $host = 'localhost'; my $port = '3306'; my $dsn = "DBI:mysql:database=$database;host=$host;port=$port"; my $user = 'root'; my $passwd = ''; # i've commented following because it fails with a "bareword" error (?) # return DECLINED if defined($r->content_type) && $r->content_type !~ m|^text/|io; my %cookies = parse CGI::Cookie($r->header_in('Cookie')); eval { tie %HTML::Mason::Commands::session, 'Apache::Session::MySQL', ($cookies{'MY_SESSION_ID'} ? $cookies{'MY_SESSION_ID'}->value() : undef), { DataSource => $dsn, UserName => $user, Password => $passwd }; }; if ($@) { if ($@ =~ m#^Object does not exist in the data store#) { tie %HTML::Mason::Commands::session, 'Apache::Session::MySQL', undef, { DataSource => $dsn, UserName => $user, Password => $passwd }; undef $cookies{'MY_SESSION_ID'}; } else { warn $@; } } if (!$cookies{'MY_SESSION_ID'}) { my $cookie = new CGI::Cookie( -name => 'MY_SESSION_ID', -value => $HTML::Mason::Commands::session{_session_id}, -path => '/', ); $r->header_out('Set-Cookie', => $cookie); } my $status = $ah->handle_request($r); $HTML::Mason::Commands::session{timestamp}=localtime; untie %HTML::Mason::Commands::session; return $status; } 1; ------ So that's it. Thanks a lot for any help in advance. This doesn't seem to be a common problem so I assume I'm going wrong somewhere obvious. Best, --Tony |