Home >Backend Development >PHP Tutorial >Some additional instructions on the use of register_globals_PHP tutorial

Some additional instructions on the use of register_globals_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:02813browse

register_globals is a configuration in php.ini. This configuration affects how PHP receives passed parameters. If your question is: Why can't my form pass data? Why can't my program get the passed variables? Wait, then you need to read the following content carefully.

The value of register_globals can be set to: On or Off. Let’s give a piece of code to describe their differences respectively.

<form name="frmTest" id="frmTest" action="URL"> 
	<input type="text" name="user_name" id="user_name"> 
	<input type="password" name="user_pass" id="user_pass"> 
	<input type="submit" value="login"> 
</form> 

When register_globals=Off, the next program should use $_GET['user_name'] and $_GET['user_pass'] to accept the passed value when receiving. (Note: When the method attribute of

is post, you should use $_POST['user_name'] and $_POST['user_pass'])

When register_globals=On, the next program can directly use $user_name and $user_pass to accept values.

As the name suggests, register_globals means registering as a global variable, so when it is On, the passed value will be directly registered as a global variable and used directly, and when it is Off, we need to go to a specific array to get it. . Therefore, friends who encounter the above problems of not being able to get the value should first check whether your register_globals setting matches your method of obtaining the value. (To view, you can use the phpinfo() function or directly view php.ini)

Then why do we use Off?

The new versions of PHP will use Off by default. Although you can set it to On, when you cannot control the server, the compatibility of your code becomes a big problem, so you'd better set it from now on. Start programming in Off style.

Now there is another question: what to do with the large number of scripts written in the On style before?

If your previous script was planned well, there is a public include file, such as config.inc.php, add the following code to this file to simulate it (this code is not guaranteed to solve your problem 100% problem, because I haven’t tested it extensively, but I think it works well). In addition, you can also refer to the solution in this post:

<?php 
if ( !ini_get('register_globals') ) 
{ 
    extract($_POST); 
    extract($_GET); 
    extract($_SERVER); 
    extract($_FILES); 
    extract($_ENV); 
    extract($_COOKIE); 
    
    if ( isset($_SESSION) ) 
    { 
        extract($_SESSION); 
    } 
} 
?> 

register_globals = Off not only affects how to obtain the data passed from and url, but also affects session and cookie. Correspondingly, the method of obtaining session and cookie should be: $_SESSION[], $_COOKIE. At the same time, there are some changes in session handling. For example, session_register() is unnecessary and invalid. For specific changes, please check the Session handling functions in the php manual

php manual wrote:

Variables provided to the script via the GET, POST, and COOKIE input mechanisms, and which therefore cannot be trusted. The presence and order of variable inclusion in this array is defined according to the PHP variables_order configuration directive.

The content in the middle of $_REQUEST actually comes from $_GET $_POST $_COOKIE. The disadvantage is that it is impossible to determine whether the variable comes from get post or cookie, which is not suitable for occasions with strict requirements.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752365.htmlTechArticleregister_globals is a configuration in php.ini. This configuration affects how php receives the passed parameters. If you The question is: Why can't my form pass data? Why...
Statement:
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