Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    sessions annoying me now.

    Hi,

    can't seem to make my session consistent from page to page

    If I refresh this one page (as shown below), it still changes the session_id each page load.

    Code:
    #!/usr/bin/perl
    
     
      use CGI;
      use DBI;
      use strict;
      use CGI qw(escapeHTML);
      use CGI::Carp qw(fatalsToBrowser);
      use CGI::Session;
    
      my $cgi                         = new CGI;
       
      my $session = new CGI::Session($cgi) or die CGI::Session->errstr;
      print $session->header; 
      my $session_id = $session->param('_SESSION_ID');
    So much at a totla loss, I can't even think what question to ask other than;
    what must I do to make sessions work.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    I have removed all other code from the file by writing it like this.

    Still, it won't hold to one session.

    Code:
    #!/usr/bin/perl
    
     
      use CGI;
      use DBI;
      use strict;
      use CGI qw(escapeHTML);
      use CGI::Carp qw(fatalsToBrowser);
      use CGI::Session;
    
      my $cgi                         = new CGI;
       
      my $session = new CGI::Session($cgi) or die CGI::Session->errstr;
      my $session_id = $session->param('_SESSION_ID');
    
      print $session->header;
      print $cgi->header;
      print $session->dump;
      print qq( $session_id  );
    
    
    exit;
    Yet this script will

    Code:
    #!/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;
    
      my $session = new CGI::Session($cgi) or die CGI::Session->errstr;
      my $session_id = $session->param('_SESSION_ID');
    
      print $session->header;
      print qq( sess_id = $session_id <br />);
    bazz
    Last edited by bazz; 07-08-2009 at 01:15 AM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Posts
    368
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Maybe I'm missing something here, but it displays the same session_id when I l refresh the page. It adds some more poop after the first refresh, but the session_id stays the same. I can even switch back and forth between both scripts, and it keeps the same session_id, as long as I don't close the browser.

  • #4
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    It doesn't with me.

    ON first page load is creates a session. On second page load it creates a new session which remains persistent until the browsaer is closed. As to why it won't create a persistent connection from the first page , I have no ideas.

    If it works perfectly on your machine does that point to me having a server issue?

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #5
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    OK, when I go straight to the page, the session loads and is persistent.

    If, however, I click a link from an outside site to the same page, the session is set (but not persistent), until I have clicked to get to a second page in the session-testing site. If I simply refresh page1 of the site, the session id changes every time.

    is this how sessions are meant to work? why does persistency behave differently, when arriving at the page in two different ways?

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Posts
    368
    Thanks
    10
    Thanked 4 Times in 4 Posts
    I made a link from another website to the session script. It created a session_id. When I refreshed the browser, it kept the exact same session_id.
    I also tried a link from the same website that hosts the script. Same result.

    I don't think it could be a server issue, since it creates a session and a cookie. I thought it might be a browser issue, but I tried it in IE and FF with the same result.

    Are all other tabs and browser windows closed when attemping the test?

  • #7
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    very curious.

    I have rewritten the script and it works. However, when I reverted to the one which has caused me trouble - didn't work, it now works too.

    No idea why but I suppose, now that it is working, it's all ticketyboo.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

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