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

Jul 13, 2016 am 10:34 AM
safety

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> 
Copy after login

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); 
    } 
} 
?> 
Copy after login

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 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Performance and security of PHP5 and PHP8: comparison and improvements Performance and security of PHP5 and PHP8: comparison and improvements Jan 26, 2024 am 10:19 AM

PHP is a widely used server-side scripting language used for developing web applications. It has developed into several versions, and this article will mainly discuss the comparison between PHP5 and PHP8, with a special focus on its improvements in performance and security. First let's take a look at some features of PHP5. PHP5 was released in 2004 and introduced many new functions and features, such as object-oriented programming (OOP), exception handling, namespaces, etc. These features make PHP5 more powerful and flexible, allowing developers to

Security challenges in Golang development: How to avoid being exploited for virus creation? Security challenges in Golang development: How to avoid being exploited for virus creation? Mar 19, 2024 pm 12:39 PM

Security challenges in Golang development: How to avoid being exploited for virus creation? With the wide application of Golang in the field of programming, more and more developers choose to use Golang to develop various types of applications. However, like other programming languages, there are security challenges in Golang development. In particular, Golang's power and flexibility also make it a potential virus creation tool. This article will delve into security issues in Golang development and provide some methods to avoid G

How to handle cross-domain requests and security issues in C# development How to handle cross-domain requests and security issues in C# development Oct 08, 2023 pm 09:21 PM

How to handle cross-domain requests and security issues in C# development. In modern network application development, cross-domain requests and security issues are challenges that developers often face. In order to provide better user experience and functionality, applications often need to interact with other domains or servers. However, the browser's same-origin policy causes these cross-domain requests to be blocked, so some measures need to be taken to handle cross-domain requests. At the same time, in order to ensure data security, developers also need to consider some security issues. This article will discuss how to handle cross-domain requests in C# development

What is the relationship between memory management techniques and security in Java functions? What is the relationship between memory management techniques and security in Java functions? May 02, 2024 pm 01:06 PM

Memory management in Java involves automatic memory management, using garbage collection and reference counting to allocate, use and reclaim memory. Effective memory management is crucial for security because it prevents buffer overflows, wild pointers, and memory leaks, thereby improving the safety of your program. For example, by properly releasing objects that are no longer needed, you can avoid memory leaks, thereby improving program performance and preventing crashes.

Security and encrypted transmission implementation of WebSocket protocol Security and encrypted transmission implementation of WebSocket protocol Oct 15, 2023 am 09:16 AM

Security and Encrypted Transmission Implementation of WebSocket Protocol With the development of the Internet, network communication protocols have gradually evolved. The traditional HTTP protocol sometimes cannot meet the needs of real-time communication. As an emerging communication protocol, the WebSocket protocol has the advantages of strong real-time performance, two-way communication, and low latency. It is widely used in fields such as online chat, real-time push, and games. However, due to the characteristics of the WebSocket protocol, there may be some security issues during the communication process. Therefore, for WebSo

Does win11 need to install anti-virus software? Does win11 need to install anti-virus software? Dec 27, 2023 am 09:42 AM

Win11 comes with anti-virus software. Generally speaking, the anti-virus effect is very good and does not need to be installed. However, the only disadvantage is that the virus is uninstalled first instead of reminding you in advance whether you need it. If you accept it, you don’t need to download it. Other anti-virus software. Does win11 need to install anti-virus software? Answer: No. Generally speaking, win11 comes with anti-virus software and does not require additional installation. If you don’t like the way the anti-virus software that comes with the win11 system is handled, you can reinstall it. How to turn off the anti-virus software that comes with win11: 1. First, we enter settings and click "Privacy and Security". 2. Then click "Window Security Center". 3. Then select “Virus and threat protection”. 4. Finally, you can turn it off

Linux server failure and security: How to manage your system healthily Linux server failure and security: How to manage your system healthily Sep 10, 2023 pm 04:02 PM

With the development of Internet technology, more and more enterprises and individuals choose to use Linux servers to host and manage their applications and websites. However, as the number of servers increases, server failures and security issues become an urgent task. This article will explore the causes of Linux server failures and how to manage and protect the system healthily. First, let's take a look at some common reasons that can cause Linux servers to malfunction. Firstly, hardware failure is one of the most common reasons. For example, the server is overheating,

Iterator safety guarantees for C++ container libraries Iterator safety guarantees for C++ container libraries Jun 05, 2024 pm 04:07 PM

The C++ container library provides the following mechanisms to ensure the safety of iterators: 1. Container immutability guarantee; 2. Copy iterator; 3. Range for loop; 4. Const iterator; 5. Exception safety.

See all articles