larryp has asked for the wisdom of the Perl Monks concerning the following question:
I'm having trouble with CGI::Session and I can't figure out what's going on. I've tried everything, POD, man pages, google, to no avail. Anyway, I know someone here will be able to point me in the right direction.
I'm using CGI::Session for session tracking. I'm creating the session, populating session parameters, and writing the CGISESSID cookie in a login script. I'm then redirecting to a page generation script. In the page generation script, I'm reading the cookie to get the session ID and then creating a new session based on the stored session id. (I'm also passing the SID of the first session in the query string for troubleshooting.) According to the documentation (tutorial, cookbook, perldoc, etc.) , this should be creating a session object associated with the established session ID instead of creating a new session. The code I'm using is as follows:
# -----8<----- my $cgi = new CGI(); my $cookieval = $cgi->cookie("CGISESSID"); my $paramval = $cgi->param("CGISESSID"); my $sid = $cgi->cookie("CGISESSID") || $cgi->param("CGISESSID"); my $session = new CGI::Session(undef, $sid, {Directory=>File::Spec +->tmpdir()}); my $sid2 = $session->id(); # -----8<-----
In this scenario, $cookieval = $paramval = $sid. These all retrieve the same session ID. However, once I create the session variable, I expect $sid2 to be the same as the previous three variables. It is not. Declaring 'my $session...' creates a brand new session object, despite the fact that I'm giving it the SID of the previous session. Once this happens, I can't access any of my previously written session parameters because $session is now associated with the new session object. I'm certain I'm doing something wrong, but I can't gure it out.
My apologies for troubling you with this and many thanks in advance for your assistance.
Thanks again,
Larry
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with CGI::Session module -- Getting a new session every time
by tachyon (Chancellor) on Nov 04, 2004 at 08:41 UTC | |
by larryp (Deacon) on Nov 04, 2004 at 17:52 UTC | |
|
Re: Problem with CGI::Session module -- Getting a new session every time
by mbeast (Beadle) on Nov 05, 2004 at 05:32 UTC | |
by larryp (Deacon) on Nov 05, 2004 at 06:21 UTC |