ryooichi Posted April 6, 2006 Share Posted April 6, 2006 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 https://forums.phpfreaks.com/topic/6745-question-about-magic_quotes_gpc-and-_session/ Share on other sites More sharing options...
wildteen88 Posted April 6, 2006 Share Posted April 6, 2006 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 https://forums.phpfreaks.com/topic/6745-question-about-magic_quotes_gpc-and-_session/#findComment-24536 Share on other sites More sharing options...
ryooichi Posted April 6, 2006 Author Share Posted April 6, 2006 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 https://forums.phpfreaks.com/topic/6745-question-about-magic_quotes_gpc-and-_session/#findComment-24538 Share on other sites More sharing options...
wildteen88 Posted April 6, 2006 Share Posted April 6, 2006 no problem. I thought you mean register_globals. I had read your post at least 10 times too. lol Link to comment https://forums.phpfreaks.com/topic/6745-question-about-magic_quotes_gpc-and-_session/#findComment-24540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.