SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Code Perl:
    #!/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

  2. #2
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •