我在尝试提交大量字段时遇到了一些问题。
所以我编写了一个脚本来测试php.ini中max_input_vars
选项的行为。
让我感到困惑。
这是我的代码:
<!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>
我用PHP 5.2和PHP 5.4进行了测试,但存在一些奇怪的差异。 似乎是在使用PHP 5.2时提交所有20000个字段的情况,尽管php.ini配置仅允许5000个。
PHP版本5.2.17中的输出:
POST-VARS COUNT: 2
POST-VARS[t] COUNT: 2000
ini_get('max_input_vars'): 5000
ISSET($_POST['submit']): TRUE
PHP版本5.4.30中的输出:
POST-VARS COUNT: 1
POST-VARS[t] COUNT: 500
ini_get('max_input_vars'): 5000
ISSET($_POST['submit']): FALSE
问题是:
有谁知道为什么php会像这样?这是PHP 5.2的错误吗?
答案 0 :(得分:2)
max_input_vars
指令可用,因为它可以在文档中看到(http://php.net/manual/en/info.configuration.php#ini.max-input-vars)。然后它不应该在PHP 5.2中工作,即使你把它放入配置并尝试ini_get()
(我猜ini_get也适用于任何不存在的指令?)。