bruce080 Posted October 2, 2009 Share Posted October 2, 2009 I have started to notice that a session variable I am using is acting rather odd. Sometimes it will work correctly and give me the value that it should have, but other times it will give me a value that it used to have. The session variable/php script works correctly 100% of the time on my local testing apache server, but when I move it from my windows box to our linux webserver, it seems to act irregularly. To narrow down the problem, my first question is, Is it possible that a $_SESSION variable could retrieve a previous value? Assuming that the answer to that question is no, then it must be an issue with my code. Quote Link to comment https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 2, 2009 Share Posted October 2, 2009 Is it possible that a $_SESSION variable could retrieve a previous value?Yes, if you actually have two separate sessions. This could occur if when you go between pages where the PATH or DOMAIN (host name/subdomain) changes in the URL and the session cookie settings are not setup to permit different path/domain values. You can also get variables that seem to change values when there is nothing in your code that causes it if register_globals are on and you have other POST/GET/COOKIE/program variables with the same name as the session variable. What does a phpinfo() statement show for the following settings - register_globals session.cookie_path session.cookie_domain Quote Link to comment https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/#findComment-929181 Share on other sites More sharing options...
bruce080 Posted October 2, 2009 Author Share Posted October 2, 2009 What does a phpinfo() statement show for the following settings - register_globals session.cookie_path session.cookie_domain register_globals Off Off session.cookie_path / / session.cookie_domain no value no value Quote Link to comment https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/#findComment-929192 Share on other sites More sharing options...
PFMaBiSmAd Posted October 2, 2009 Share Posted October 2, 2009 The third setting would cause any switching back and forth between www.yourdomain.com and yourdomain.com to give two different sessions. Are you redirecting or have links that would cause pages to be reached both with and without a www. on the URL? Beyond that, perhaps pages are being cached on one system and not the other so that visiting a dynamically updated page shows the previous contents instead of the changed value. If you force your browser to refresh the page, do the values show up correctly? Quote Link to comment https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/#findComment-929198 Share on other sites More sharing options...
bruce080 Posted October 2, 2009 Author Share Posted October 2, 2009 If I force my browser to refresh the page, the values show up correctly. This means that my linux webserver is caching the values? Quote Link to comment https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/#findComment-929201 Share on other sites More sharing options...
bruce080 Posted October 2, 2009 Author Share Posted October 2, 2009 How do I fix this problem? Quote Link to comment https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/#findComment-929242 Share on other sites More sharing options...
PFMaBiSmAd Posted October 2, 2009 Share Posted October 2, 2009 Adding these header statements to your pages should prevent the browser/proxy/server from caching the content - <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> Quote Link to comment https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/#findComment-929310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.