Jump to content

Archived

This topic is now archived and is closed to further replies.

ryooichi

Question about magic_quotes_gpc and $_SESSION

Recommended Posts

I have a PHP application doing MySQL-based sessions on 2 different Windows 2003 Server machines running Apache2 (Win32) and one has PHP 5.0.5 and the other 5.1.2. On both, in php.ini, magic_quotes_gpc is set to off.

On the machine running PHP 5.0.5, everything is working fine. But using PHP 5.1.2, I seem to be having an issue where setting a regular scalar variable whose name happens to match a key in the $_SESSION variable, is referring to the same thing. This reminded me to check what magic_quotes_gpc was set to and confirmed that it was in fact set to off.

For example, I have a session variable stored in $_SESSION['username'] and can correctly print out its value before I set an assumingly separate variable, $username to '' (an empty string). Afterwards, when I print out the value of $_SESSION['username'] it now reflects '' (an empty string).

I.E.:
[code]$_SESSION['username'] = 'ryooichi';
print "\$_SESSION['username'] = \"{$_SESSION['username']}\"<br>\n"; # prints: $_SESSION['username'] = "ryooichi"
$username = '';
print "\$_SESSION['username'] = \"{$_SESSION['username']}\"<br>\n"; # prints: $_SESSION['username'] = ""[/code]

So my question is: what is going on here?

Of course, my current workaround is simply to not use $username as the name for my other variable and have changed it to just $user and the conflict has now ceased. I would just like to understand it and hopefully learn how can I control this behavior.

Thank you.

Share this post


Link to post
Share on other sites
FYI magic_quotes_gpc doesn't affect variable names. The only thing it does affect is the value a variable contains such as if a variables value contains quotes magic_quotes_gpc eacapes any quotes.

Now I think what you meant was register_globals rather than magic_quotes_gpc. register_globals should be off on both servers.

I tried your script provded above on my local server running PHP 5.1.2 and $username doesn't affect $_SESSION['username'] at all.

You must have something else that is set which is affecting variable names.

Share this post


Link to post
Share on other sites
I was just reading my php.ini for the 43rd time today and comparing it to the one on the other machine and you are right. On the machine having problems, register_globals was on. I tested it both ways and this was the culprit. Thank you for the quick response and pointing me in the right direction.

Share this post


Link to post
Share on other sites
no problem. I thought you mean register_globals. I had read your post at least 10 times too. lol

Share this post


Link to post
Share on other sites

×

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.