Try looking at Apache::Session in tandem with Apache::Cookie. The former sets up a hash that can be used to store any user specific data and retrive it in subsequent requests by referencing a unique key. The later helps you manage cookies that can be used to store your unique session key on the browser side.

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.

use 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;
Hope this helps

Edit: Typos, add links to cpan

/\/\averick


In reply to Re: mod_perl and multiuser global variables by maverick
in thread mod_perl and multiuser global variables by rsennat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.