phphttp-post-vars

Why is max_input_vars ignored in PHP 5.2?


I had a little issue while trying to submit a large number of fields. So I wrote a script to test the behaviour of the max_input_vars option in php.ini.

It confuses me.

This is my code:

<!doctype html>
<html>
<body>

<?php

$t = array();
if(isset($_POST['t'])) { $t = $_POST['t']; }

echo "POST-VARS COUNT: ". count($_POST)." <br />";
echo "POST-VARS[t] COUNT: ". count($t)." <br />";

echo "ini_get('max_input_vars'): ". ini_get("max_input_vars"). "<br />";
echo "ISSET(\$_POST['submit']): ". (isset($_POST['submit']) ? "TRUE" : "FALSE"). "<br />";
echo "<br />";

echo "<form method='post' action='{$_SERVER['PHP_SELF']}'>\n";

for($j = 0; $j < 2000; $j++) {
    for($i = 0; $i < 10; $i++) {
        echo "<input type='hidden' name='t[$j][$i]' value='$i' />\n";
    }
}
echo "<input type='submit' name='submit' value='test'>\n";

echo "</form>\n";

?>

</body>
</html>

I tested it with PHP 5.2 and PHP 5.4 and there are strange differences. It seems to be the case that all 20000 fields are submitted when using PHP 5.2 although the php.ini configuration allows only 5000.

The Output in PHP Version 5.2.17:

POST-VARS COUNT: 2
POST-VARS[t] COUNT: 2000
ini_get('max_input_vars'): 5000
ISSET($_POST['submit']): TRUE

The Output in PHP Version 5.4.30:

POST-VARS COUNT: 1
POST-VARS[t] COUNT: 500
ini_get('max_input_vars'): 5000
ISSET($_POST['submit']): FALSE

The Question is:

Does anyone know why php behaves like this? Is it a bug of PHP 5.2?


Solution

  • max_input_vars directive is available since PHP 5.3.9 as it can be seen in the documentation ( http://php.net/manual/en/info.configuration.php#ini.max-input-vars ). Then it is not supposed to work in PHP 5.2 even if you put it into the config and try an ini_get() (I guess ini_get would work for any non-existence directive as well?).