SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_SESSION gets reset!

    I have a "simple" login.php file that sets the $_SESSION['user'] variable upon successful login.

    The $_SESSION['user'] is passed to all pages just fine. However when I load the front page of the site (main.php) weirdness happens. On this page, the variable shows up again (I tried an echo on the variable), but upon leaving the main.php page to go to another page (where the variable was previously being passed) the variable no longer shows!

    I'm not sure why this is happening. main.php starts with the following as recommended by other boards:

    session_start();
    header("Cache-control: private"); // IE 6 Fix.

    Any ideas why the $_SESSION variable would be reset upon loading this page? I'd have something to work with if the variable wasn't showing on this page, but it does show, it just disappears altogether after leaving the page. I then have to force the user to login again.

    Help!

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at all the code in that script that touches anything session related.

    See if your session id changes as well.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked main.php and there are no references to $_SESSION. However, it makes a call to a sidebar file (left.php) through an include near the top of the file which includes the following lines:

    Code:
    $query="select PASSWD,ISLOGIN,NAME,LASTNAME from USER where LOGIN='".$_SESSION['username']."'";
    $conn -> Query($query);
    $user = $_SESSION['username'];
    $pass = @$conn -> Get_Record_Item("PASSWD");
    ?>
    
    <SOME HTML HERE>
    
    <? if (!$_SESSION['username'] || $_SESSION['password']!=$pass || !$islogin): ?>
    
    <SOME HTML HERE>
    Also, I checked left.php and it includes the following at the top of the file:
    Code:
    <?
    // start the session 
    session_start(); 
    header("Cache-control: private"); //IE 6 Fix 
    ?>
    Through some debug statements, I can see that $_SESSION is maintained within left.php, but after navigating to another page from here, the $_SESSION variable gets lost.

    Pls help me from going bokers on this!

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    print_r($_COOKIE);

    make sure the browser is sending the session cookie.

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK problem solved and it turns out (as is almost always the case) it was human error...I had recently included calls to the Wordpress blog on our site which required inclusion of Wordpress config files...when I dug deeper into one of the required config files being called from main.php it was specifically unregistering all globals and session array variables set!

    So the fix (albeit ugly) was to copy the $_session values into a temp variable before the call to the Wordpress config files and then to set the $_session variable back to the temp variable after the Wordpress calls.

    Thanks for all those that tried to help.


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
  •