I am using Mason 2, Apache 2, mod_perl 2 and I have been banging my head
against a brick wall trying to get session ids to work.  The code below has
been working pewrfectly on my development PC, but has suddenly refused to
work any longer when called remotely.

I use a global variable declared in my httpd.conf (these work perfectly)

MasonAllowGlobals %MyGlobal
PerlAddVar MasonAllowGlobals $MyDbh
PerlAddVar MasonAllowGlobals $MyDiag

In perl-HTML-Mason.conf I have the following modules loaded at startup:

PerlOptions +GlobalRequest
PerlModule Apache2::Request
PerlSetVar MasonArgsMethod mod_perl
PerlModule Apache::DBI
PerlModule Apache2::RequestUtil
PerlModule Apache2::Cookie
PerlModule Digest::SHA1
PerlModule Digest::MD4
PerlModule Apache2::Connection
PerlModule Apache2::RequestRec
PerlModule Apache2::Request
PerlModule Apache2::Const
PerlModule APR::Table
PerlModule APR::Request
PerlModule APR::Request::Cookie

In my autohandler I have the following code for cookies/sessions (all
variables declared using strict):
# fetch inbound cookie

$req = APR::Request::Apache2->handle ($r);
$cookie_in = undef;
$jar = $req->jar;
if ($jar) {
   $cookie_in = $jar->get("$SessionName");
   if ($cookie_in) {
       $cookie_val = "$cookie_in";
   }
}

# If no cookie, create it.

if (not $cookie_in) {
   $cookie_val = Digest::SHA1::sha1_hex (time, rand, $$);
}

# Save cookie for login/out and basket.

$MyGlobal{'SessionId'} = $cookie_val;
$SessionId = $MyGlobal{'SessionId'};

# generate new cookie

$cookie_out = APR::Request::Cookie->new (
   $req->pool,
   name => "$SessionName",
   value => $cookie_val,
   domain => "metsys2.dev",
   expires => '+20m'
);

$cookie_out->version(1); # upgrade it to conform with RFC 2109/2965.

# send a response header

bake ($cookie_out, $r);

-----------------------------------

All I want is to generate reliable session ids.
Does anyone have any working code that I can use?

Jim Rey
--
Jim Rey
48 Laburnum Park
Bradshaw
Bolton BL2 3BU
United Kingdom
Tel: 01204 593 222
Mob: 07816 751 874
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to