View Full Version : still got a session problem.
OK, I still don't seem to be able to get this session issue resolved.
It's like this:
I have four scripts which need to use the same session.
In each script I call in a 'header' file, which outputs the html head part of the document. Having got the session to work for all four scripts, I must put 'print $cgi->header;' into the header file. This means that on every page, I have the session header printed along the top.
I have tried, and failed, to work out a way of having different client's headers work with these four files. Maybe that is where the solution lies?
here is the code for each script.
use strict;
use CGI::Session;
my $session = new CGI::Session($cgi); or die CGI::Session->errstr;
print $session->header;
That maintains session in all scripts. However, header.pl which only outputs the html head section, needs to be told what format it is in eg
print 'Content-type: text/html'."\n\n";
or
print $session->header;
or
print $cgi->header;
Any of those causes the display of the session data at the top and if I remove whichever I have used, the whole page outputs as a text file.
What do I need to do to get the header file to display properly without showing the session data in the outputted html page?
totally stumped:(
bazz
This might also help.
(updated session system)
script 1 - shows available rooms and loads the session
script2 - loads the session and shows the details of a specific, chosen room (from script 1) and puts the room-specific data into the session.
script3 - loads the session and shows the room data and costs for the selected stay as well as showing a form for inputting the personal details of the guest.
the header script (header.pl), shows the html head section and starts the session.
in each script, the header.pl file is required before the session->load command.
What I find is that by script 2, the session isn't performing (no error). If a go back from script 2 to script 1 and refresh, then it works if I then progress through the booking process.
This is the code for scripts 1-3
#!/usr/bin/perl -w
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;
use DBI;
use Date::Manip;
use CGI::Session;
use POSIX;
my $cgi = new CGI;
use Date::Parse;
use Date::Format;
use Data::Dumper;
use lib '../cgi-bin/';
use lib '/var/www/vhosts/mydomain/subdomains/cms/cgi-bin/';
use lib '/var/www/vhosts/mydomain/subdomains/cms/cgi-bin/EazyModules/';
#require 'bookings_system_session.pl';
#my $session = get_bookings_session();
#my $session_ID = $session->param('_SESSION_ID');
#print $session->header;
require 'header_control.pm'; # locate headers and footers module
my $session = CGI::Session->load($cgi) or die CGI::Session->errstr;
# my $session = new CGI::Session($cgi);# or die CGI::Session->errstr;
print $session->header;
and this is the code for the header.pl file
#!/usr/bin/perl -w
use CGI;
use CGI::Session;
use strict;
use lib '../cgi-bin/';
use lib '/var/www/vhosts/mydomain/subdomains/hotel/cgi-bin/';
use lib '/var/www/vhosts/mydomain/subdomains/cms/cgi-bin/';
use lib '/var/www/vhosts/mydomain/subdomains/cms/cgi-bin/EazyModules/';
my $cgi = new CGI;
use DBI;
my $session = new CGI::Session($cgi); or die CGI::Session->errstr;
print $session->header;
Maybe I'll have to put the header content directly into the scripts but I was hoping to have 1 header file per client.
bazz
FishMonger
06-08-2008, 05:17 PM
The html headers should only be printed once for any given page. Remove the printing of the content-type header in the "header file" and any other "downstream script" that is loaded via a "use" or "require" statement and print the $session->header in the main script.
FishMonger
06-08-2008, 06:11 PM
I think your life, and these scripts, would be easier with the use of HTML::Template
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm
oesxyl
06-08-2008, 06:43 PM
print $cgi->header, $session->header and "Content-Type: text/html\n\n" is same thing with some difference and replace one others. More exactly each one add some thing and from your point of view $session->header add the send cookie stuff. That means that instead of print $cgi->header and all the stuff for sending cookie you just use $session->header.
That's why FishMonger said to use it only once and to be before any other print you have.
I hope this make things more simple, :)
regards
FishMonger
06-08-2008, 07:17 PM
I see a flaw in your design and implementation. You didn't provide any details on what the "header file" does, but presumably it needs to use some data stored in the session. There are several approaches you can take to fix this dilemma, but the easiest might be to pass the session ID as a parameter to the header script and then have it load/use the session data but not print the html/session header.
Thanks to you both.
The header file simply outputs the html head section of the page. This includes the logo and strapline for a business. (Fish I don't know if you looked at the link I sent you a couple of weeks ago). It doesn't need to do anything with regard to the session. I was just trying to get the session to work for all three scripts but not, to output the session data to the web page.
If I run the session in the scripts, and I remove print $cgi->header from the header.pl file, the whole page outputs as text. If I add what is necessary to avoid this, I get the session data outputted to each page.
The html headers should only be printed once for any given page. Remove the printing of the content-type header in the "header file" and any other "downstream script" that is loaded via a "use" or "require" statement and print the $session->header in the main script.
That's what I have already done. I can get all three scripts to work by using 'print $session->header;' But, unless I add that line or one of the others 'print $cgi->header' or 'print Content-type:etc' in the header file, the whole page outputs as text.
I'll check out that module FishMonger and see if I can 'get it'.
bazz
OK,
each script calls the header.pl file before loading the session. and the header file creates a new session if there isn't already one started. So, if I run script one it doesn;t load the session, however, if I refresh the page, it does, and then it all works tickety boo from then on.
So what would be the reason for the script one, not loading the session which has been created as soon as the header file was included?
script one runs the header file and afterwards is meant to load the session.
bazz
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.