Jump to content

[SOLVED] PHP Session Help


NoSalt

Recommended Posts

Hello All

 

    I have a site that I'm working on that has a log-in system. The problem lies in the SESSION variables. When I go from one specific  page to another specific page I loose all of the SESSION variables I have saved. The strange thing is that on my local system, this doesn't happen at all; the problem is only on my hosting service servers. The SESSION variables hold for all pages except for going from this one page to another and it's driving me batty. Any information you may have on this would be GREATLY appreciated and would save my sanity.

 

Thanks For Reading  :)

Link to comment
https://forums.phpfreaks.com/topic/125722-solved-php-session-help/
Share on other sites

You likely have a header problem. Add the following two lines immediately after your first opening <?php tag on both the page where you set the session variables and on the page where they don't work -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

PFMaBiSmAd

 

I made the change you suggested and it showed no errors.

 

Dark Water

 

Your suggestion was definitely part of the problem. It seems that now I have a new one. Now when I "attempt" to go from the one page to the other, the site locks up. In order to access the site again (any part of it, not just those two pages) I have to delete the session variables from Firefox and log back on. I looked at the apache error logs but there isn't anything there either. I've never seen anything like this and it's really bizarre.

 

 

Thank you both for reading and replying.

Well ... after a little research (ok ... a LOT of research) I believe I have found the problem. I was moving from one page to the other page via PHP's "header" function. This is what I had:

 

    if(($_SESSION['loggedIn'] && $_SESSION['viewUUID']) && ($_SESSION['uuid'] == $_SESSION['viewUUID'])){
        header("Location: ./newpage.php");
    }

 

I was reading more on the PHP.net and I saw that people were using the "exit" command to stop execution of code further down the page. Well, I guess I wrongfully assumed that once the "header" function worked it's magic that I would no longer be on the page, so I didn't think I needed anything else. I guess I was wrong. I changed the code to:

 

    if(($_SESSION['loggedIn'] && $_SESSION['viewUUID']) && ($_SESSION['uuid'] == $_SESSION['viewUUID'])){
        header("Location: ./shame.php");
        exit;
    }

 

and the page works just as I intended.

 

Thanks to all who read and replied.  :)

 

 

Php code on a page executes until it reaches the end of the page or until it reaches an exit/die statement. If your code on the page after the header() statement deletes the session or sets session variables to something else, than that is what value they will have in them. A header() is simply sent to the browser. For a redirect, the browser fetches the URL that is was given in the header() statement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.