Jump to content

Question about magic_quotes_gpc and $_SESSION


ryooichi

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.
Link to comment
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.

Link to comment
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.
Link to comment
Share on other sites

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.