NoSalt Posted September 25, 2008 Share Posted September 25, 2008 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 More sharing options...
PFMaBiSmAd Posted September 25, 2008 Share Posted September 25, 2008 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); Link to comment https://forums.phpfreaks.com/topic/125722-solved-php-session-help/#findComment-650084 Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 Also, are you going from like, http://phpfreaks.com to http://www.phpfreaks.com and it's dropping? (notice the www) That could be a php.ini mix up. Link to comment https://forums.phpfreaks.com/topic/125722-solved-php-session-help/#findComment-650090 Share on other sites More sharing options...
NoSalt Posted September 25, 2008 Author Share Posted September 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/125722-solved-php-session-help/#findComment-650104 Share on other sites More sharing options...
NoSalt Posted September 25, 2008 Author Share Posted September 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/125722-solved-php-session-help/#findComment-650421 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2008 Share Posted September 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/125722-solved-php-session-help/#findComment-650430 Share on other sites More sharing options...
NoSalt Posted September 25, 2008 Author Share Posted September 25, 2008 I guess I assumed that it was like "exec" in C ... once called and executed the current process disappears. Of course, my CS prof. always said to check the return value of exec. Thanks for all your help and input. Link to comment https://forums.phpfreaks.com/topic/125722-solved-php-session-help/#findComment-650438 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.