Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php Post limited to 1000 variables

Tags:

I've got a large form and I can see from firebug that all of the elements' values are being sent properly, but when I print_r($_POST) there are only 1000 variables displayed. My max_post_size is set to 25M so I know that's not the issue and I searched through my php.ini for keywords like 'post' and 'max' and I didn't find anything.

1000 is only about 1/4 of the elements that I'm passing so obviously this is a pretty big issue for me, I really appreciate any help I can get.

like image 273
jreed121 Avatar asked Feb 29 '12 19:02

jreed121


People also ask

How can change maximum number of POST variable in PHP?

By default, the maximum number of input variables allowed for PHP scripts is set to 1000. You can change this amount by setting the max_input_vars directive in a php. ini file.

What is the default maximum size of POST in PHP INI of?

The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.

What is $_ POST [] in PHP?

PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post".

How does $_ POST work?

The $_POST variable collects the data from the HTML form via the POST method. When a user fills the data in a PHP form and submits the data that is sent can be collected with the _POST Method in PHP. The Post Method transfers the information via the Headers.


4 Answers

I see what you did here.

max_input_vars, 1000

Introduced in order to prevent hash collision attack: http://www.phpclasses.org/blog/post/171-PHP-Vulnerability-May-Halt-Millions-of-Servers.html But failed in 5.3.9: http://www.phpclasses.org/blog/post/175-Another-Serious-Security-Bug-on-PHP-539.html So you should update to 5.3.10+ if that is problem.

like image 72
Dejan Marjanović Avatar answered Oct 22 '22 13:10

Dejan Marjanović


I had a similar situation; I could only POST the first 1000 elements of an array.

My solution was to implode() the array into one long string and explode() it on the server side.

json_encode() could probably work as well.

like image 39
Thunder Rabbit Avatar answered Oct 22 '22 13:10

Thunder Rabbit


I had that exact same problem of the 1000 variable limit using PHP v5.4.20. Even though the php.ini file did not contain any such 'max_input_vars' line, I simply found a convenient place to slot it in under the top [PHP] section, added the line 'max_input_vars = 10000', restarted Apache and everything was solved.

like image 38
RobOrland Avatar answered Oct 22 '22 13:10

RobOrland


Ok. I've figured out a solution using jquery

I did it like this

$("#single-form").submit(function(event) {
    event.preventDefault();
    var table_data = $(this).serialize();
    console.log(table_data);
  // ajax call to handle the data
}

serialize function will give the URL encoded strings of all form data and in PHP file just use the function parse_str to parse the string into variables.

like image 45
Jay Maharjan Avatar answered Oct 22 '22 14:10

Jay Maharjan