CluelessNoob
CluelessNoob

Reputation: 696

Cannot change PHP post variable limit

I am using LAMP on Ubuntu 12.04 . PHP version is 5.3.10-1ubuntu3.9

I cannot change the maximum post input variable limit. Here is my php.ini file: http://paste.ubuntu.com/6941021/

Note, I have these settings:

max_input_vars = 5000
max_input_nesting_level = 64
upload_max_filesize = 64M
post_max_size = 64M

Even then, the limit seems to be set to 1001 (yeah 1001, for some odd reason not 1000).

Here are the 2 test files:

test.php

<!DOCTYPE html>

<html>



<head>
    <title>Test</title>
</head>



<body>
    <form method=post action=test2.php>
        <input type=submit value="Let's go" /><br /><br />

        <?php
            for ($i=1; $i <= 1100; $i++)
            {
                echo "<input type=text name=$i value=$i /><br />\n";
            }
        ?>

        <input type=submit value="Let's go" />
    </form>
</body>



</html>

test2.php

<!DOCTYPE html>

<html>



<head>
    <title>Test 2</title>
</head>



<body>
    <?php
        for ($i=1; $i <= 1100; $i++)
        {
            $num = $_POST[$i];
            echo "Num: $num<br />";
        }
    ?>
</body>



</html>

The output of test2.php is like this:

Num: 1
Num: 2
Num: 3
.
.
.
Num: 999
Num: 1000
Num: 1001
Num:
Num:
Num:
Num: 
.
.
.

What am I missing? Thanks in advance :)

Upvotes: 2

Views: 2298

Answers (3)

Ankur Garg
Ankur Garg

Reputation: 605

I solve this issue by adding the following line in apache configuration file.

php_value max_input_vars 2000

Location of configuration file is CENTOS : etc/httpd/conf/httpd.conf UBUNTU : etc/apache2/apache2.conf

After adding these file restart apache. Now you can post any number of variable.

Upvotes: 0

Satish Saini
Satish Saini

Reputation: 2968

Well, it should work after setting max_input_var = 5000 in php.ini. Try to debug it using .htaccess file OR send all the post parameters as a single parameter separated by a unique identifier like "@#" and then split that string in another files using explode function of PHP into an array and use that array for further computation.

OR change your code like this:

 <?php
            for ($i=1; $i <= 1100; $i++)
            {
                echo "<input type=text name=a[] value=$i /><br />\n";
            }
 ?>

See I have given same name to all the fields where a is a blank array. When you click on send button, it will send an array in post and then on next page you can use given code to parse all the values

<body>
    <?php
        $finalarray = $_POST['a'];
        $count = count($finalarray);
        for ($i=0; $i <= $count; $i++)
        {
            $num = $finalarray[$i];
            echo "Num: $num<br />";
        }
    ?>
</body>

I hope it will work fine.

Upvotes: 2

julienhaversano
julienhaversano

Reputation: 446

Not sure why you would be sending 1100 POST variables all by the name of numbers...

Anyways, the minimum amount of POST variables is 1000, this could be either upto the browser or your php config. Try changing max_input_vars in php.ini. I wouldn't suggest doing this as it may not work on all browsers (as some have a limit).

Upvotes: 0

Related Questions