T
TonyV
I've been beating myself up over this one for a few days. If anyone
can help me out, I'd greatly appreciate it.
I'm running Windows Server 2003 with ActiveState Perl. The perl -v
command gives me this:
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
....
Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com
Built Jan 23 2007 15:57:46
I downloaded CGI-Session-3.95.zip from ppm.activestate.com and
installed it by running ppm install CGI-Session.ppd. The server is
IIS v6.0, and the local IIS user account has read/write access to my
sessions directory.
I'm trying to do something that I think should be stupidly simple:
Save a variable to a session and retrieve it. What's happening,
though, is that every time I visit the page, it's creating a new
session. Even simply refreshing the page creates a new session.
Here's my code, which I tried to boil down to a very simplified case.
----------------------------------------
use strict;
use CGI::Session;
use CGI;
my $cgi = new CGI;
my $session = new CGI::Session(undef, undef, {Directory=>'/websessions/
test'}) or die CGI::Session->errstr;
my $cookie = $cgi->cookie(CGISESSID => $session->id );
# Print the cookie header with the session ID in it.
print $cgi->header(-cookie => $cookie);
print $cgi->start_html(-title=>'Test Page');
# See if first_name is defined as a query parameter. If it is,
# set the first_name session parameter.
my $name = $cgi->param('first_name');
if (defined $name and $name ne '')
{ $session->param('first_name', $name); }
# If it's not, try getting it from the first_name session
# parameter.
else
{ $name = $session->param('first_name'); }
# If it's not in the query parameters or the session parameters,
# set it to a default.
if (!defined $name or $name eq '')
{
$name = 'stranger';
$session->param('first_name', $name);
}
# Greet the user.
print $cgi->h1("Hello, $name!");
print $cgi->end_html;
----------------------------------------
Like I said, when I load the page, a new session file is created in
the /websessions/test directory. If I hit the refresh key, a new
session is created. If I tag on a ?first_name=Foomonkey, I get
greeted with Hello, Foomonkey!, and a new session is created. Then if
I take it back off, yet another new session is created.
I do have cookies enabled in my browser, I've tried it with the same
result from Firefox and IE. The following is returned by my server in
the header Although, of course, the date and the CGISESSID are
different with each page load. The date should be. The CGISESSID
shouldn't be. >:-(
Set-Cookie: CGISESSID=3b2b11be7bf4de7d79a828c8389eb413; path=/
Date: Thu, 15 Mar 2007 22:14:01 GMT
Content-Type: text/html; charset=ISO-8859-1
I'm at my wit's end. Am I doing something stupid wrong in the code?
Does anyone know of any issues with my setup? (IIS 6.0 on Windows
Server 2003, ActiveState Perl 5.8.8, build 820, CGI-session 3.95.)
can help me out, I'd greatly appreciate it.
I'm running Windows Server 2003 with ActiveState Perl. The perl -v
command gives me this:
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
....
Binary build 820 [274739] provided by ActiveState http://www.ActiveState.com
Built Jan 23 2007 15:57:46
I downloaded CGI-Session-3.95.zip from ppm.activestate.com and
installed it by running ppm install CGI-Session.ppd. The server is
IIS v6.0, and the local IIS user account has read/write access to my
sessions directory.
I'm trying to do something that I think should be stupidly simple:
Save a variable to a session and retrieve it. What's happening,
though, is that every time I visit the page, it's creating a new
session. Even simply refreshing the page creates a new session.
Here's my code, which I tried to boil down to a very simplified case.
----------------------------------------
use strict;
use CGI::Session;
use CGI;
my $cgi = new CGI;
my $session = new CGI::Session(undef, undef, {Directory=>'/websessions/
test'}) or die CGI::Session->errstr;
my $cookie = $cgi->cookie(CGISESSID => $session->id );
# Print the cookie header with the session ID in it.
print $cgi->header(-cookie => $cookie);
print $cgi->start_html(-title=>'Test Page');
# See if first_name is defined as a query parameter. If it is,
# set the first_name session parameter.
my $name = $cgi->param('first_name');
if (defined $name and $name ne '')
{ $session->param('first_name', $name); }
# If it's not, try getting it from the first_name session
# parameter.
else
{ $name = $session->param('first_name'); }
# If it's not in the query parameters or the session parameters,
# set it to a default.
if (!defined $name or $name eq '')
{
$name = 'stranger';
$session->param('first_name', $name);
}
# Greet the user.
print $cgi->h1("Hello, $name!");
print $cgi->end_html;
----------------------------------------
Like I said, when I load the page, a new session file is created in
the /websessions/test directory. If I hit the refresh key, a new
session is created. If I tag on a ?first_name=Foomonkey, I get
greeted with Hello, Foomonkey!, and a new session is created. Then if
I take it back off, yet another new session is created.
I do have cookies enabled in my browser, I've tried it with the same
result from Firefox and IE. The following is returned by my server in
the header Although, of course, the date and the CGISESSID are
different with each page load. The date should be. The CGISESSID
shouldn't be. >:-(
Set-Cookie: CGISESSID=3b2b11be7bf4de7d79a828c8389eb413; path=/
Date: Thu, 15 Mar 2007 22:14:01 GMT
Content-Type: text/html; charset=ISO-8859-1
I'm at my wit's end. Am I doing something stupid wrong in the code?
Does anyone know of any issues with my setup? (IIS 6.0 on Windows
Server 2003, ActiveState Perl 5.8.8, build 820, CGI-session 3.95.)