PHP $ _ REQUEST array Security Risks

Source: Internet
Author: User

We all know that using $ _ REQUEST directly saves the need to judge post and get some code, which is easier to use. However, if we want to think about it in detail, we will think that $ _ REQUEST is terrible. See the analysis below.

We all know that to process form data, we can use PHP's $ _ GET and $ _ POST super global variables, specifically the method specified when the form is submitted. In addition, PHP also provides a $ _ REQUEST array. But it not only contains all the data elements of $ _ GET and $ _ POST, but also contains all the data elements of the $ _ COOKIE ultra-Global Array.
But have you ever wondered, if the keys in these three groups are the same, which array value do I use $ _ REQUEST to obtain? Will there be any problems?
I will use the following code for your demonstration. Because I just want to explain the problem, we do not set $ _ COOKIE here. Please handle it by yourself:

The Code is as follows: Copy code
<? Php
Var_dump ($ _ GET ['a'], $ _ POST ['a'], $ _ REQUEST ['a']);
?>
<Html>
<Head> <title> demo </title> <Body>
<Form method = 'post' action = 'req. php? A = XXX'>
<Input type = 'did' name = 'A' value = 'yyy'/>
<Input type = 'submit 'name = 'submit' value = 'submit '/>
</Form>
</Body>
</Html>

When I submit a form, the page content I obtain is:

String (3) "xxx" string (3) "yyy" string (3) "yyy"

Similarly, in $ _ REQUEST, the POST value overwrites the GET value. What is the problem?
In fact, this is set in the PHP configuration file. Let's take a look at the php. ini configuration file, which contains the following content in line 466th:

The Code is as follows: Copy code

; This directive describes the order in which PHP registers GET, POST, Cookie,
; Environment and Built-in variables (G, P, C, E & S respectively, often
; Referred to as EGPCS or GPC). Registration is done from left to right, newer
; Values override older values.
Variables_order = "EGPCS"

This EGPCS indicates the priority of the content obtained using the $ _ REQUEST array. The letter Meanings of the EGPCS are: E-generation table $ _ ENV, G stands for $ _ GET, P stands for $ _ POST, C Indicates $ _ COOKIE, and S indicates $ _ SESSION. The subsequent data will overwrite the previously written data. The default data writing method is EGPCS. Therefore, the data contained in the POST will overwrite the data with the same keywords in GET.


$ _ REQUEST [] uses the $ _ POST [] $ _ GET [] function, but $ _ REQUEST [] is slow. All data submitted through the post and get methods can be obtained through the $ _ REQUEST array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.