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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
nemws1Database 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.