Forum Moderators: coopster
If you enable register_globals in PHP you don't have to use $GLOBALS['varname'] to access a variable. Since it is switched off be default and considered to be good style to leave it off, I wonder if it is givig me some security risk to have it enabled.
So is it safe to switch it on?
Thanks in advance!
my personal opinion is don't do it
php_flag register_globals 0 to the root level .htaccess file. As none of my scripts need Register Globals to be on, is it a good idea to disactivate it?
$var = $somevalue;
You don't think about it and you build a form with
<input type="hidden" name="var" value="someothervalue">
Now what value does $var have?
In most cases, I think globals make things confusing and can encourage logic errors in the code. If I want one, let me declare it, but I don't want any automagic globals.
given that the variable order is Environment, GET, POST, Cookie, Server (EGPCS)
someone passing variables in the url
script.php?foo=badvalue
can corrupt other superglobal arrays.
The key to hacking a script is to understand the data, if someone can get bad values into your code then they can possibly start understanding the structure of the environment and even the structure of your db, among other things. Then from thre exploit different values/variables and learn more etc, etc ....
It is a slippery slope and really depends on what someone is trying to do. They may just be messing around, they may want to wipe your db, who knows but allowing anything passed to your script into the scripts scope always struck me as a very bad idea. You need to then adjust for an infinite number of possible variables floating around in your script. If globals is off you can focus on controlling the values of the known vars.
1. Do not use GOTO statements
2. Avoid globals if at all possible.
3. If it doesn't fit on a page of printout, it needs to be broken down into functions
I've broken #3 more times than I can count (liek yesterday for example) and don't think it makes sense really, but the other two I've happily stuck with since I think it's hard enough to follow my spaghetti logic without adding in features that make it even harder ;-)