Craig79 Posted December 7, 2008 Share Posted December 7, 2008 Hello, I installed PHP5, Apache2, and MySql5 on Ubuntu Linux 8.10. I use this script to verify that someone has been verified from a previous page: if ((isset($SESSION[sesone])) && (isset($SESSION[sestwo]))) { // the user was validated on a previous page } else { // they have not been validated on the previous page } I checked the output of the session variables on the page that set them by echoing them out after they had been set. That works. I used this to set the variables: $SESSION[sesone] = $myvarBut when I redirect to another page, the session variables are empty. What happened? This works on one of my sites running PHP 4.3. Is that the difference? Other info: --------------------------------------- every page begins with session_start(); Session support: enabled session.use_cookies: on register_globals: off Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2008 Share Posted December 7, 2008 Add the following two lines immediately after your first opening <?php tag (and before the session_start()) on both the page where you set the session variable and on the page where you are trying to use the session variable - ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708287 Share on other sites More sharing options...
Craig79 Posted December 7, 2008 Author Share Posted December 7, 2008 Thank you - that indeed does look helpful. Here's what I got: Notice: Use of undefined constant sesone - assumed 'sesone' in /var/www/fitness/createtasks.php on line 25 Notice: Undefined index: sesone in /var/www/fitness/createtasks.php on line 25 Notice: Use of undefined constant sestwo - assumed 'sestwo' in /var/www/fitness/createtasks.php on line 25 Notice: Undefined index: sestwo in /var/www/fitness/createtasks.php on line 25 My note: Line 25 has this: echo 'sesone is ' . $_SESSION[sesone] . ' and sestwo is ' . $_SESSION[sestwo] . '<br>'; Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708300 Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2008 Share Posted December 7, 2008 Those two error message are telling two things - 1) The proper syntax is (missing quotes on associative array index names) - echo 'sesone is ' . $_SESSION['sesone'] . ' and sestwo is ' . $_SESSION['sestwo'] . '<br>'; 2) Whatever page that is, the session variables don't exist. Either they were not set, the session id was not propagated between pages by the browser, or the session variables got overwritten by your code or by register_globals. Is the setting you show for register_globals from a php.ini setting or from the actual value that a phpinfo() statement shows? Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708329 Share on other sites More sharing options...
Craig79 Posted December 7, 2008 Author Share Posted December 7, 2008 Thank you very much: it's getting better. With the single quotes, I now get: Notice: Undefined index: sesone in /var/www/fitness/createtasks.php on line 25 Notice: Undefined index: sestwo in /var/www/fitness/createtasks.php on line 25 ...instead of... Notice: Use of undefined constant sesone - assumed 'sesone' in /var/www/fitness/createtasks.php on line 25 Notice: Undefined index: sesone in /var/www/fitness/createtasks.php on line 25 Notice: Use of undefined constant sestwo - assumed 'sestwo' in /var/www/fitness/createtasks.php on line 25 Notice: Undefined index: sestwo in /var/www/fitness/createtasks.php on line 25 Odd how the quotes never mattered before, but I'm just greatful to find the fix. Now the only thing that remains is the Undefined Index Yes, the variables I posted were from the output of phpinfo() Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708336 Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2008 Share Posted December 7, 2008 That leaves - Either the session variables were not set, the session id was not propagated between pages by the browser, or the session variables got overwritten by your code. There is probably another possibility - the session data file is being deleted on every session_start() statement. Start checking on your server and in your browser to determine which of these things are occurring or not. Is the session data file getting created and does it remain for a while. Is the session id cookie present in the browser? Did this problem correspond to a change in your code and you would need to post both the code that sets the session and the code that uses the session for anyone in a forum to help with what they might be doing to cause this symptom. BTW: These errors - Use of undefined constant sesone - assumed 'sesone' in ... were always occurring with that code but the error reporting settings were hiding them. However, php make as assumption (stated in the error message) so the code functions, but it take 10-20 times longer for each line of code with that error in it to be executed because of the error response logic php goes through to try to find first a constant by that name and then look up an actual array index by that name. Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708375 Share on other sites More sharing options...
Craig79 Posted December 7, 2008 Author Share Posted December 7, 2008 Thank you - I'll troubleshoot these. As for the 'sesone' session variable, I don't think it's not occuring on my other site due to the error reporting being off. If the variable was not passed and verified, this would mean that the user is not authenticated and they would be given an error display. I've tested it dozens of times with different user accounts, in IE and FireFox, and they all work. The only difference is that this instance is running on a different platform: Ubuntu 8.10. On IIS and CentOS I have had no problems. I did check the session file and i did NOT see a session id in it. What could that be? It just had session names and variables, and the correct value for the variables were there. I'm completely puzzled. Also, I've tried these, but they didn't work: -------------------------------------------- session_commit() before redirecting to new page changed the session.save_path to a directory with complete read/write privileges (I restarted Apache after making changes to the php.ini) Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708383 Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2008 Share Posted December 7, 2008 Some possibilities associated with the browser not passing the session id between pages would be if the pages had different host names/subdomain or had different paths and the session cookie settings where not setup to allow the session cookie to be passed between these. Do the URL's of the two pages have different host names/subdomains, like www.yourdomain.com and just yourdomain.com and/or yourdomain.com/somepath/file1.php and yourdomain.com/someotherpath/file2.php? Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708389 Share on other sites More sharing options...
Craig79 Posted December 7, 2008 Author Share Posted December 7, 2008 Your last post got me really thinking, and the problem is now solved! I was using http://localhost/ in my redirects (header). I changed all instances of 'localhost' to '127.0.0.1' , like this: http://127.0.0.1/ Holy cow I spent 8 solid hours on this. I'm really glad it's working now though! Thank you so much for your help! Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708411 Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2008 Share Posted December 7, 2008 Cookies (including session id cookies) are domain specific. I would recommend either using relative URLs or forming an absolute URL using $_SERVER variables so that you don't have domains/localhost/ip addresses hard coded in your script. Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708535 Share on other sites More sharing options...
kenrbnsn Posted December 7, 2008 Share Posted December 7, 2008 Are you calling <?php session_start(); ?> at the start of each script where you want to use sessions? Ken Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708607 Share on other sites More sharing options...
Craig79 Posted December 7, 2008 Author Share Posted December 7, 2008 Thanks again PFMaBiSmAd! Yes, Kenrbnsn, I called session_start() at the top of each page. Link to comment https://forums.phpfreaks.com/topic/135873-solved-all-of-a-sudden-my-session-variables-get-dropped/#findComment-708755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.