Perl Sessions

See the code below. It is a part of a perl script that is embedded into a html file like this:
<iframe src="cgi-bin/script.pl" Width=90% height=320>

Everytime I reload the page I get a _new_ session id printed. I would assume that I would want to load the same session to access the stored data within and not create a new session every time the page loads?
What do I need to do?


my $cgi=new CGI;
my $currentPagePosition;
$session = new CGI::Session(undef, $cgi, {Directory=>"/tmp"});

if(!$session->param('pagePosition')) {
	$session->param('pagePosition', 0);
} else {
	$currentPagePosition = $session->param('pagePosition');
}
my $id = $session->id();
print $id;

Open in new window

LVL 2
itniflAsked:
Who is Participating?
 
nemws1Connect With a Mentor Database AdministratorCommented:
Yes - you want to use the header() call from the CGI::Session module in order for the session to work correctly.  Change line 4 in your code from a blank line to:
print $session->header();

Open in new window

0
 
FishMongerCommented:
Where's your cookie and header creation/output?

Based on what you've posted, I'd expect it to generate an "Internal Server Error" since there was no output of the html header prior to the "print $id;" statement.
0
 
FishMongerCommented:
Please post a short but complete script that demonstrates the problem.
0
 
itniflAuthor Commented:
Yes, that worked, but now I am getting:
"Content-Type: text/html; charset=ISO-8859-1"
in the html file from the print $session->header(); statement.
0
 
nemws1Database AdministratorCommented:
Odd.  It shouldn't.  Can you post more of the HTML code (including the iframe you mentioned above)?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.