I just suddenly starting having the weirdest problem I've ever seen, and nothing has changed except the host of my site. I use a lot of $_SESSION variables in my code that might have the same name as a normal variable, but setting the normal variable seems to be changing the $_SESSION variable with the same name.
For example, if I do
$_SESSION['favcolor'] = 'blue';
$favcolor = 'green';
echo $_SESSION['favcolor'];
I get green
as the response... How do I not let this happen? I figure there's most likely some PHP ini variable that must be changed but I can't seem to find anything on this...
SOLUTION
So since I'm on an different host to host my site, I had to go by this in the following way. I created a php.ini
file and put it in the root of my site's files with just the following line in it:
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 doing a little further research; variables and session variables shouldn't ever be the same anyways. It's a good practice that I will start to use throughout the rest of my programming.
Looks like register_globals
is turned on. That will cause conflicts like you're experiencing. Your host probably forgot to turn them off when configuring the server. Once they do, your issue should go away.
If they refuse to turn it off, find a new host. Not only should register_globals
be turned off, but they've been deprecated and will be removed in the next version of PHP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With