Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/176303-inconsistent-session-variables/
Share on other sites

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

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?

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
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.