Setting PHP Standard Variables Changing Session Variables

I just unexpectedly start with the strangest problem I have ever seen, and nothing has changed except the host of my site. I use many $ _SESSION variables in my code, which may have the same name as a normal variable, but usually changing a normal variable changes the $ _SESSION variable with the same name.

For example, if I do

$_SESSION['favcolor'] = 'blue'; $favcolor = 'green'; echo $_SESSION['favcolor']; 

I get green as an answer ... How can I prevent this from happening? I suppose, most likely, some kind of PHP ini variable that needs to be changed, but I cannot find anything in this ...


Decision

So, since I am on a different host to host my site, I had to go through this as follows. I created a php.ini and placed it in the root of my site files with only the following line:

 register_globals = Off ;notice the capital 'O' in 'Off' 

Then, in my .htaccess file, I added this to the end of the file:

 <IfModule mod_suphp.c> suPHP_ConfigPath /home/myhostusername/public_html/stumpyinc.com <Files php.ini> order allow,deny deny from all </Files> </IfModule> 

No more conflicting variables! I also learned something from this experience and did some further research; variables and session variables should never be the same. This is a good practice that I will start using throughout my programming.

+6
source share
1 answer

It looks like register_globals on. This will cause conflicts like the ones you are experiencing. Perhaps your host forgot to disable them when setting up the server. Once they do, your problem should disappear.

If they refuse to disable it, find a new host. Not only will register_globals be disabled, but they are deprecated and will be removed in the next version of PHP.

+9
source

All Articles