in reply to mod_perl and multiuser global variables
The problem that you're running into isn't really one of keeping a value shared, it's one of making sure you have the same value for the same browser session. Since HTTP is stateless, you have to have the browser pass back to the server on each request (either via cookie or URL parameter) the unique identifier of the session.
It's Monday AM...let's see if I can whip out a working example.
Hope this helpsuse Apache::Cookie; use Apache::Session::File; # Inside your mod_perl handler my $cookie = Apache::Cookie->new($r, -name => 'session_id', -expires => '+1D', -domain => 'mysite.com', -path => '/' ); my %session; my $session_id = $cookie->value; # The tie will fail if the session_id isn't valid or is missing. Thus + the need for eval. eval { tie(%session,'Apache::Session::File',$session_id, { Directory => ' +/tmp', LockDirectory => '/tmp' }); }; if ($@) { # bogus session_id. Setting it to undef will cause Apache::Sessio +n to create a new one undef $session_id; tie(%session,'Apache::Session::File',$session_id, { Directory => ' +/tmp', LockDirectory => '/tmp') || die "say something useful"; } if ($session_id != $cookie->value) { # session id has changed or is a new one; update the cookie $cookie->value($session_id); $cookie->bake; } # use %session at will to store user data. $session{'name'} = 'John Doe'; $session{'user_id'} = 123; my $value = $session{'some_data'}; # untie the session after you're done with it untie %session;
Edit: Typos, add links to cpan
/\/\averick
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: mod_perl and multiuser global variables
by rsennat (Beadle) on Dec 05, 2005 at 15:44 UTC | |
by wazzuteke (Hermit) on Dec 05, 2005 at 15:51 UTC | |
by maverick (Curate) on Dec 05, 2005 at 16:14 UTC | |
by rsennat (Beadle) on Dec 05, 2005 at 15:56 UTC | |
by Moron (Curate) on Dec 05, 2005 at 16:56 UTC |