How to obtain the submitted data in the parsing sequence of PHP variables _ PHP Tutorial

Source: Internet
Author: User
Tags form post server array
This article describes how to obtain the submitted data in the parsing sequence of PHP variables. Since the submitted URL is not notified, this BUG has been active until today. However, this BUG does not occur in every commit. after several tests, it is found that

Since the submitted URL is not notified, this BUG has been active until today. However, this BUG does not occur during each submission. after several tests, it is found that this BUG only occurs when multiple consecutive submissions occur. Because the submitted form is complex and involves several input parts, it is suspected that an error occurs in the intermediate link.

The troubleshooting process is var_dump ($ _ REQUEST) in each process. Therefore, an error is found during the second consecutive submission. when the first form is submitted to the second form, the $ _ REQUEST array is changed. Here, we need to look at the $ _ REQUEST array again:

The manual describes the variables submitted to the script via GET, POST, and COOKIE mechanisms, so this array is not trustworthy. In this way, the var_dump ($ _ REQUEST) is decomposed into var_dump ($ _ POST), var_dump ($ _ GET), and var_dump ($ _ COOKIE). The problem is clearer, in order to save values in multiple single-room page tables, the COOKIE was tried. although The expire item is not set, the COOKIE is destroyed when the SESSION ends, however, if multiple advertisements are submitted consecutively in one session, the value of form POST will be overwritten by the value previously saved in the COOKIE, and only some errors occur, the COOKIE variable name is prefixed when it is saved to the COOKIE, except for the url variable, the same variable name is used.

The problem is found, but there are new questions: why does the COOKIE overwrite the POST instead of the opposite for the same variable name? So we finally came to the variables_order setting item in the title. The original text in php. ini is as follows:

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.

This setting describes the PHP variable parsing sequence, including $ _ GET, $ _ POST, $ _ COOKIE, $ _ ENV, $ _ SERVER array,
The resolution sequence is left to right, and the new value is parsed to overwrite the old value. The default value is EGPCS (Environment, GET, POST, Cookie, Server ).
If it is set to "GP", PHP will completely ignore the environment variables, cookies and server variables, and overwrite the same name variables of the GET method with the variables of the POST method.

Conclusion:

As mentioned in the manual, $ _ REQUEST is an array that is not trustworthy. To avoid similar problems as much as possible, the $ _ POST or $ _ GET array should be explicitly used to obtain the submitted value.

In special cases, you can adjust the variables_order settings so that you can always obtain the submitted data you want to obtain.


Bytes. However, this BUG does not occur in every commit. after several tests, it is found that only connection...

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.