Why is POST data truncated by PHP? - php

I have a pretty big form with many-many items in it. After upgrading to PHP 7, in the new environment some of the POST elements are not received by the server. The $_POST array is not empty, it contains many elements, but some of the elements from the end of the $_POST array is missing.
No error messages appear.
Increasing post_max_size in php.ini (from 8M to 128M) did not help. The data structure itself is not too big, less than 400k, so this shouldn't be the reason.
Why can this be?

As of PHP 5.3.9. a new php.ini setting exists called max_input_vars. It determines how many items can be used from the received data. By default it is 1000 which means that only the first 1000 items from $_POST will be used.
So, if increasing the post_max_size does not help then try to increase max_input_vars from 1000 to 5000 or whatever you need.
More info: PHP Manual for max_input_vars

Related

$_POST not containing all input data

I'm trying to post a large form through php using POST method. My form post script has been working fine until now that the $_POST array got pretty large.
When i print out file_get_contents('php://input'); ,all the inputs that are included in the form, are shown. But when i print out $_POST, it only gets the first part of the form. I've tried to remove rows and then the $_POST method works fine again. As soon as it gets too large, it won't post all data included in the form.
Anyone got any ideas? I've tried to edit php.ini and set post_max_size to a higher value, but it didn't help either.
By default, in lower versions of PHP(< 5.3.9) the number of $_POST variables is limited to 1000. There is no way to change that.
In higher versions you can set max_input_vars to whatever number you wish.
If you're below 5.3.9 there are some work-arounds you can do. For example json_encode the variables and send them as a single variable. The limit of $_POST is set to 8mb by default but can be changed in the php.ini file post_max_size="whatever_size_you_wish_here".
How to increase the number of variables in $_POST:
2 options:
in your .htaccess file do php_value max_input_vars 2000(or whatever)
in the file you're working with ini_set('max_input_vars', 2000);
Try dumping a phpinfo() and look for max_input_vars. If it's there, you can set it in php.ini to a higher number, as you see fit. If you don't see it, it's likely that you didn't receive that exact patch and the number has been hard-coded by your distribution.
Just solved it, apparently my server didn't update max_input_vars for some strange reason. Now that i increased that value it's working.

Long PHP FORMs are cut off when they are submitted

I have one page with a large form inside: Table with more than 2000 vars.
I know about max_input_vars and in my php.ini I set:
max_input_vars = 3000
But the problem is the same.
If I make the count, only 1000 variables are returned.
When I am using
var_dump(ini_get('max_input_vars'));
The result is 3000:
Do you know where I can be wrong?
I am using symfony, is tehre any difference?
If you exceed max_input_vars you would get a PHP Warning: Input variables exceeded 1000 so it must be related to something else.
First you need to make sure that the browser is sending all the data. You can do some debugging via browser console, eg. serialize the form $('#form').serialize() and inspect it or count the number of inputs within the form, or post the values and inspect the HTTP message; most probably you will find that the browser is not sending the whole form for some reason.
The problem was fixed with the bagonyi's help.
In fact, I was using suhoin and I had to set in my php.ini:
[suhosin]
suhosin.request.max_vars = 10000
suhosin.post.max_vars = 10000
That resolved the problem.

How to check if my form is reaching the post limit

I have a large HTML form which I think is reaching the php post limit because the last parts of the data are getting missed off although it there anyway to test/be sure that this is the cause?
I understand this can easily be fixed by increasing the php.ini values, but is there anyway in PHP to check this is the cause in PHP?
e.g: it writes a log showing the amount of posted data sent by the form and checks this against the value in the php.ini
If your php installation is using suhosin, ensure that the following values are appropriate:
suhosin.request.max_vars
suhosin.post.max_vars
They will limit the number of accepted POST variables php receives (http://forums.digitalpoint.com/showthread.php?t=1513000).
To find the length of the POST data, you may be able to use $HTTP_RAW_POST_DATA http://php.net/manual/en/reserved.variables.httprawpostdata.php
There are three factors
Post_max_size in PHP (use phpinfo() for get limit)
LimitRequestBody in Apache
MaxClientRequestBuffer on IIS

PHP and (too) many input fields

I've got a html-form with roughly ~1500 input fields* (either text or hidden).
The form.action is POST and every inputfield has a unique name (no name=foo[]).
Whenever I try to print every variable of $_REQUEST in PHP after the form is submitted, only the first few entries are printed. In fact, the $_REQUEST variable only contains 1001 items (so about 500 fields are missing).
Any idea why this happens ?
Since data are sent via post not get, the url-limit is not a problem. So I thought that it had something todo with the config of the webserver and that the request was too big. But setting LimitRequestBody to 0 doesn't changed anything in the result.
In terms of memory used by this PHP-array I only read that the size is only limited by the overall memory, which should be more than enough. (keys are about 20chars each, and the value is about 6chars each)
Do I miss something?
*In case you wonder: the navigation consists of about 750 entries, 2 fields per entry (one position for ordering and one for parent if nested)
Since PHP 5.3.9 there's a new configuration setting called "max_input_vars" which limits the number of input variables. The default setting is 1000. Also check if Suhosin is installed, because there's also a similar setting.
Although, I would recommend to reduce the number of fields if possible.
Try to override php_flag max_input_vars.
Add to your .htaccess file or change php.ini
php_flag max_input_vars 1500
There is also a flag for nesting
php_flag max_input_nesting_level 64
Perhaps you exceed the size of a POST? yo could use mime multipart, like people do wen are posting files.
Check your php.ini configuration for the post_max_size value - perhaps you have exceeded it?

PHP: whats the total length of a post global variable?

I was wondering if anybody knows the total length that a post global could be. e.g:
$_POST['formInput'] = "hello world, how long can i be?";
I am creating a site where someone will enter an unknown amount of chars into a textarea, so potentially it could be 2 pages on a word document. So if anybody knows of any other methods of how i can do this apart from using a post global? (it cant be saved in a file, as its important data that i dont want other people to find) That would be very helpful.
Thanks
Check your php.ini for post_max_size. This is typically about 8mb by default, but if you're on shared-hosting, it could definitely vary.
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
You'll have to use $_POST if you wish to send large amounts of data to the server. For further study, I'd suggest checking out POST Method Uploads in the documentation.
$_POST is populated from the body of a HTTP-request. Since there are no restrictions on the size of a HTTP-request, there are no restrictions in the protocol layer. However PHP has some limitations on how much input it will read. You can control this with the ini-setting post_max_size
Another problem can be the default limit in php.ini for directive max_input_vars (default 1000), not only the post_max_size. If you have e.g. a very large form with thousands of checkboxes the $_POST array will have only 1000 keys.
If you want some large amount of data sent from the browser to the server, you'll have to use HTTP POST method -- which means the data will be received, on the PHP side, in the $_POST superglobal array ; there's not much you can do about that.
The configuration directive post_max_size defines the maximum amount of data that can be received using the POST method -- you might need to set that to a value higher than the default one, depending on your needs.
And, as said on the documentation of post_max_size, the value set for memory_limit can also have its importance.

Categories