Forum Moderators: coopster
My register_globals is on, and it's annoying me. And I have been reading up on the register_globals issue. And it's hard to understand.
Here's what's happening to me:
$_SESSION['user'] = "bob";
echo $_SESSION['user']; // bob
echo $user; // bob
$user = 'sam';
echo $_SESSION['user']; // sam
This is insane! Now everytime I make a local variable I have to worry weather it is overwriting $_SESSION or $_GET? How can I avoid this?
I've also noticed that the following will overwrite the _SESSION var:
$_SESSION['name']= "jim";
print ($_SESSION['name']); // jim
$name = "bob";
print ($_SESSION['name']); // bob
But it won't overwrite _GET:
../url/path?name=jim
print ($_GET['name']); //jim
$name = "bob";
print ($_GET['name']); //jim
What is the possible benefit of overwriting the session info? Is this a bug or pure silliness?
I had no idea it would do that, it should only poison the local variable
this should still output jim both times
$_SESSION['name']= "jim";
print ($_SESSION['name']); // jim
$name = "bob";
print ($_SESSION['name']); // bob
even though register_globals is quite bad I don't think that is how it is supposed to work. What version of php are you using? it might be worth checking [bugs.php.net] if that bug was present in any versions, never heard of it though.
You might want to talk to your host and see if it is an option to turn off register_globals. If it isn't you could look at this page as to some ways of dealing with it
[php.net...]
$_SESSION['name']= "jim";
print ($_SESSION['name']); // jim
$name = "bob";
print ($_SESSION['name']); // bob
But even weirder is that it doesn't happen on the first load of the session, only the second load and after! Screw it, I'm getting register_globals off at all costs!
It seems senseless, but I don't really have the time to see if it's a bug or not.