Session not initialising on first page - terring hair out

Hi,

I have the following code, which creates a session everytime - but - it only makes a session persistent from the second page viewed. If I go to the website and just refresh the first page I land on, a new session is created everytime. Not until I go to a second page is the session created, which is used on every subsequent page. page 1’s session id is never persistent.

I have tried everything I can find in the cpan tutorial but to no avail.


#!/usr/bin/perl 

  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 CGI::Cookie;

   my $sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
  my $session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
   print $session->header;
 #my $session = new CGI::Session($cgi) or die CGI::Session->errstr;
  my $cookie = $cgi->cookie(CGISESSID => $sid );
  my $session_id = $session->id();
  
  print qq( cookie=$cookie :sid=$sid :sess_id = $session_id <br /> );


bazz

Aw!! I found the problem to be caused because when going to ‘page 1’, it is an shtml page which redirects to the perl script. If I access the perl file directly, all works fine.

bazz