简体   繁体   中英

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?

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?).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM