Home  >  Article  >  Backend Development  >  What to do if the data submitted by the php form is lost

What to do if the data submitted by the php form is lost

藏色散人
藏色散人Original
2020-07-11 10:52:423193browse

Solution to PHP data loss: first check the integrity of the form submission request; then check whether the request data exceeds the PHP or nginx limit; then obtain the original request directly through "file_get_contents('php://input')" Data; last modified max_input_var quantity.

What to do if the data submitted by the php form is lost

Data loss problem in PHP form submission

I encountered a small problem when processing user excel import today

The requirements are as follows: after the user imports excel, use PHPExcel to read the imported data, render a form, and the user confirms the integrity of the imported data by viewing the form, and finally confirms the entry into the database.

What to do if the data submitted by the php form is lost

However, due to the user's excel importing a lot of data, there are more than 6,000 inputs after the form is rendered, and the form submission (POST) is directly used, resulting in only A small portion of the previous data can be read.

Tracking

1. Check the integrity of the form submission request

By tracking the http request during submission, it is found that all data is submitted normally.

2. Check whether the request data exceeds the php or nginx limit

By looking at the Content-Length under Request Headers, it is found that it is only 218558 B, which is about 20KB. This definitely doesn't meet the limit.

3. Obtain the original request data directly through file_get_contents('php://input')

Since only a small part of the data is obtained by directly using $_POST, use php:// directly. input obtains the original input data. When printing it out, it is found that the data obtained by this kind of sending is complete.

4. Parse the original request parameters through the function parse_str

When I parse the original input data with parse_str

...
$origin = file_get_contents('php://input');
parse_str($origin, $result);
var_dump($result);

I got an error

Warning: parse_str(): Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini

At this point, I should understand what the problem is.

5. Modify the number of max_input_var in php.ini

# 默认的 php.ini 配置
# How many GET/POST/COOKIE input variables may be accepted
# max_input_vars = 10000

The default configuration only allows the maximum number of inputs for requests (GET/POST/COOKIE) to be 1,000.

After appropriately modifying the value of max_input_var in php.ini, the problem is solved.

Of course, the final solution is to submit json format data through ajax. After all, modifying the configuration of php.ini is still not ideal!

End

Because I didn’t notice that PHP has this limitation, I overturned here

For more related knowledge, please visit PHP Chinese website !

The above is the detailed content of What to do if the data submitted by the php form is lost. For more information, please follow other related articles on the PHP Chinese website!

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