I am writing a PHP website. I have a $_SESSION['id'] that hold the username id of a user, which I will use this value later on in my scripting. However, I notice that the ID changes as I surf the site.
Is id reserved in any way? Or, should I change id to something else?
This problem is happening whenever I click on a button several times. I am 100% sure that I’m not altering $_SESSION['id'] beyond the initial login.
Could someone please help me understand what is happening, and how it can be fixed.
I am going to assume you already use
session_start, if not see the other comments 😛If you have register globals on, you may be seeing behavior like that if you use the variable
$idin your code. As a test, try:Reload the page a couple times. If
barprints out rather thanFoo, that may be your problem. You’ll probably want to make the session variable name something that is less likely to get used elsewhere, or (more correct) turn off register globals.