php内新的限制:每个POST有1000个字段。 有人知道,如果数量可以受到影响?

在较新的PHP版本中,每个公式的input文件数(POST)将被限制为1000(未validation的信息)。 它接缝这个限制已经安装在5.2的某些版本。 这在我们的网上商店造成了很多问题。

有人知道更多关于它,如果这个限制可能会受到参数或variables的影响。 我只是发现max_input_vars,但它似乎是一个完整的5.4.RC4新的变种而且我不知道,如果这个变种将是一个POST方法。

 max_input_vars 

是PHP解决一些安全问题的一个尝试,当它被设置时,它会限制你input的数量(因此,你的表单中的字段)。 也要小心

 max_input_nesting_level 

是的 – 他们是可configuration的。 只需编辑您的php.ini或htaccess值。

我也遇到过这个问题,正在对我的代码进行本地化安装,Debian Sid已经升级到5.4 RC4 PHP。 超过7000行的checkbox(!)的forms突然只处理了$ _POST数据…头几个小时的头1001这些。

在/etc/php5/apache2/php.ini中进行更改:

 max_input_vars = 5000 

保存并重新启动apache,现在都很好。

如果你不能/不想增加服务器限制,这是另一种解决scheme

 <!-- 10000 checkboxes outside the FORM. You do not want to post this --> <input class="cbox" type="checkbox" value="1" id="id-1" checked name="id[]"> .... <input class="cbox" type="checkbox" value="10000" id="id-10000" checked name="id[]"> <form method="POST" action="postpage.php"> <input type="hidden" id="cboxes" name="cboxes" class="cboxes" value="" /> <input type="submit" onclick="return clicked();"> </form> 

然后使用jQuery

 <script> function clicked() { var cb = $('.cbox:checked').map(function() {return this.value;}).get().join(','); $('#cboxes').val(cb); return true; } </script> 

使用POST我testing了发布10000条logging。

在服务器中

 $cboxes = $_POST['cboxes']; $cbox_exp =(explode(',', $cboxes)); print_r(count($cbox_exp)); //gives me 10000 

只是想总结和指出一些事情:

1)限制可以是PHP,如上所述。

2)限制可以是上面提到的web服务器。

3) Suhosin限制只适用于安装。 设置在php.ini中更改

4)如果您尝试在URL中提交大量数据,请小心浏览器URL长度限制

更改任何服务器设置后重新启动Web服务器。

显然它看起来像一个补丁在Linux环境造成这个问题。 如果你的服务器有这个补丁“suhosin”,可能是这个问题。 也不可能在运行时重写这个,而是包含在你的php.ini

 suhosin.post.max_array_depth suhosin.post.max_array_index_length suhosin.post.max_name_length suhosin.post.max_totalname_length suhosin.post.max_vars suhosin.post.max_value_length 

将所提交的一些数据串联起来总是好事 – 而不是在PHP中改变这个限制。 例如,如果您通过Ajax或通过表单字段发送内容,则只需将导致问题的字段串联起来即可。

如果有意义的话,限制是在字段的“数量”而不是“长度”。

这些变化往往是有据可查的。 你确定它被回溯到5.2吗? 你在哪里读过? 看起来你更有可能碰到一些其他的限制,比如post_max_size或Apache的LimitRequestFields ,甚至像Suhosin这样的PHP安全模块。

(此外,PHP 5.2不再支持,所以我怀疑它会得到这样的升级。)

如果您不使用多个或多个input字段,则可以使用任何特殊字符连接多个input,例如@

 <input type='text' name='hs1' id='hs1'> <input type='text' name='hs2' id='hs2'> <input type='text' name='hs3' id='hs3'> <input type='text' name='hs4' id='hs4'> <input type='text' name='hs5' id='hs5'> <input type='hidden' name='hd' id='hd'> 

使用任何脚本(JavaScript或JScript)

 document.getElementById("hd").value = document.getElementById("hs1").value+"@"+document.getElementById("hs2").value+"@"+document.getElementById("hs3").value+"@"+document.getElementById("hs4").value+"@"+document.getElementById("hs5").value 

有了这个概念,你将绕过max_input_vars问题。 如果在php.ini文件中增加对服务器有害的max_input_vars 。 因为他们使用更多的服务器caching,有时他们会崩溃的服务器。