# Get the incoming cookies my %cookies = parse CGI::Cookie($r->header_in('Cookie')); # Try to re-establish an existing session eval { tie %HTML::Mason::Commands::session, 'Apache::Session::DBI', ($cookies{'AF_SID'} ? $cookies{'AF_SID'}->value() : undef), { DataSource => $dbsource, UserName => $dbuser, Password => $dbpass }; }; # If we could not re-establish an existing # session, create a new session. if ( $@ ) { if ( $@ =~ m/^Object does not exist in the data store/ ) { tie %HTML::Mason::Commands::session, 'Apache::Session::DBI', undef, { DataSource => $dbsource, UserName => $dbuser, Password => $dbpass }; undef $cookies{'AF_SID'}; } } if ( !$cookies{'AF_SID'} ) { my $cookie = new CGI::Cookie(-name => 'AF_SID', -value => $HTML::Mason::Commands::session{_session_id}, -path => '/',); $r->header_out('Set-Cookie', => $cookie); } my $status = $ah->handle_request($r); untie %HTML::Mason::Commands::session; return $status;