Home > Backend Development > PHP Tutorial > About the problems you will encounter after register globals is turned on_PHP tutorial

About the problems you will encounter after register globals is turned on_PHP tutorial

WBOY
Release: 2016-07-13 17:48:43
Original
855 people have browsed it

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.


Excerpted from kaituozhe345

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478397.htmlTechArticleI read the PHP manual and it said that global variables are recommended to be turned off, that is, set regester_globales to off, and the manual also mentioned An example is given to illustrate what problems will occur if it is not turned off, such as...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template