$_POST not containing all input data - php

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.

Related

Size of post too big

I got a database that currently is pretty big (and even gets bigger by time).
I got a webpage on which I present the data in a form, so it can be changed.
I send it with method post.
This worked pretty well until the data got too much. Now it tells me 'it exceeds the limit of 1000'.
I read that I could change post_max_size in php.ini but I cant do it on my webserver, so its not really an option for me. Is there anything else I can do? The problem is, that ALL THE SHOW data will be in post, not only the changed one. Is there something that would do the trick?
I don't know the type and setup of your web-server, but post_max_size can be set in an .htaccess file:
php_value post_max_size 10000
Alternatively you could only send the values that have changed. If you use ajax to post your form, you could set - and check for - for example a data attribute like modified set on the fields.
By the way, I am assuming that you are talking about individual posts and are not sending your whole database back-and-forth. If you offer editing of a collection of items, you should use something like pagination to limit the number to a fixed maximum.

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