1

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?

steven
  • 4,868
  • 2
  • 28
  • 58
  • 1
    Just forget about 5.2. Really - it's an ancient version, why worry? – Alma Do Jul 15 '14 at 06:48
  • @Alma Do It is just running on my host because i havn't refractored my hole code until now. I work on it. I will use PHP 5.4 asap. – steven Jul 15 '14 at 06:53
  • http://php.net/manual/en/info.configuration.php does it answer you question? – Royal Bg Jul 15 '14 at 06:53
  • @RoyalBg hmmmmm... Available since PHP 5.3.9. So it shouldn't show 5000 if i do a `ini_get`. Sorry, if that is the reason, this is really a silly question. Please post at least an answer to let me accept it. – steven Jul 15 '14 at 07:00
  • @steven I guess, you can set into the php.ini a dummy directive, which lately you can extract with `ini_get()`. `ini_get()` is used to try to see how a directive is set/changes, rather than if it's compatible with the version/build – Royal Bg Jul 15 '14 at 07:05

1 Answers1

3

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

Royal Bg
  • 6,988
  • 1
  • 18
  • 24