Hammy has asked for the wisdom of the Perl Monks concerning the following question:
# pull in the required packages use Apache::Session::MySQL; use Apache; use strict; # read in the cookie if this is an old session my $r = Apache->request; my $cookie = $r->header_in('Cookie'); $cookie =~ s/SESSION_ID=(\w+)/$1/; # create a session object based on the cookie we got from the # browser, or a new session if we got no cookie my %session; eval { tie %session, 'Apache::Session::MySQL', $cookie, {DataSource => 'dbi:mysql:sessions', UserName => $db_user, Password => $db_pass, LockDataSource => 'dbi:mysql:sessions', LockUserName => $db_user, LockPassword => $db_pass, }; }; if ($@) { # could be a database problem die "Couldn't tie session: $@"; } # might be a new session, so let's give them their cookie back my $session_cookie = "SESSION_ID=$session{_session_id};"; $r->header_out("Set-Cookie" => $session_cookie);
|
|---|