session variables lost unexpectedly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxoulmate
    New Member
    • May 2007
    • 77

    session variables lost unexpectedly

    why there's an instance.
    my page been session timeout.

    code something like this:
    Code:
    //login page
    session_start();
    $_SESSION['var1'] = "username";
    //will be redirected to main.php when logged in
    header('location:main.php');
    Code:
    //main.php
    session_start();
    echo session_id();
    foreach($_SESSION as $key=>$value)
    {
    echo $key." = ".$value."<br>";
    }
    when i refresh the page of main.php
    sometime i get no session.
    something like all my session variables been gone.
    but the sessionid still the same.
    my script didnt unset or use session_destroy ()
    therefore it must be there.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    You might be sending the header due to content in your PHP file before session start.

    Make sure the first character in your PHP file is <?php. No spaces or anything else. Those should be on the first line, first character of the file. And make sure you immediately call session_start() without echoing or doing anything else.

    Let me know if that worked or not.

    Comment

    • xxoulmate
      New Member
      • May 2007
      • 77

      #3
      session start is at the begginning of the script.
      and there is no space either on the first line.

      is it something to do with what they call garbage collector.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        and there is no space either on the first line.
        you may not always see the characters, ref. http://bytes.com/topic/php/insights/...s-already-sent

        on the other hand side, if there were indeed whitespace, it would have triggered a warning.

        is it something to do with what they call garbage collector.
        that would depend on your session settings in php.ini

        Comment

        • xxoulmate
          New Member
          • May 2007
          • 77

          #5
          yep it was., it will trigger warning of character already established.,

          my system has a an option of session length: forever
          but theres' a time (no definite time). all session variables gone. so my system logout the user. That's really the problem.

          Comment

          Working...