Clicky

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;                             
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 

Select allOpen in new window

asked 12/05/2011 03:32

itnifl's gravatar image

itnifl ♦♦


5 Answers:
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.
link

answered

FishMonger's gravatar image

FishMonger

Please post a short but complete script that demonstrates the problem.
link

answered 2011-12-05 at 12:08:53

FishMonger's gravatar image

FishMonger

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:
1:
print $session->header();
link

answered 2011-12-05 at 12:10:09

nemws1's gravatar image

nemws1

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.
link

answered 2011-12-05 at 13:11:15

itnifl's gravatar image

itnifl

Odd.  It shouldn't.  Can you post more of the HTML code (including the iframe you mentioned above)?
link

answered 2011-12-05 at 20:50:58

nemws1's gravatar image

nemws1

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 12/05/2011 03:32

Seen: 219 times

Last updated: 12/08/2011 05:45