I read the PHP manual and it said that global variables are recommended to be turned off, that is, set register_globales to off
And the manual also gives an example to explain what problems will occur if it is not turned off. The example is as follows, but the explanation part behind it
GET auth.php?authorized=1 Don't know what it means? ? ? I hope everyone can help me
Example of incorrect use of register_globals = on
// When the user is legal, assign $authorized = true
if (authenticated_user()) {
$authorized = true;
}
// Since $authorized is not initialized to false in advance,
// When register_globals is turned on, the variable value may be defined by GET auth.php?authorized=1
// So anyone can bypass authentication
if ($authorized) {
include "/highly/sensitive/data.php";
}
?>
When register_globals = on, the above code will be dangerous. If it's off, $authorized can't be changed via things like URL requests, which is much better, although initializing variables is a good programming practice. For example, if $authorized = false is added before the above code is executed, it does not matter whether register_globals is on or off, because the user status is initialized as unauthenticated.