php 中的新限制:每个 POST 1000 个字段。有人知道,是否可以影响数字?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8710185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
new limit within php: 1000 fields per POST. Does someone know, if the number can be influenced?
提问by Peter
In newer PHP-Versions the count of input-fileds per formula (POST) will be limited to 1000 (unverified information). It seams that this limit is already installed in certain builds of 5.2. This causes a lot of problems at our online shop.
在较新的 PHP 版本中,每个公式 (POST) 的输入文件数将限制为 1000(未经验证的信息)。看起来这个限制已经安装在 5.2 的某些版本中。这给我们的网上商店带来了很多问题。
Does someone know more about it and if this limit could be influenced by parameters or Vars. I just found max_input_vars, but it seems to be a complete new var of 5.4.RC4 And I'm not sure, if this var will be the one for the POST method.
有人知道更多关于它的信息,以及这个限制是否会受到参数或变量的影响。我刚刚找到了 max_input_vars,但它似乎是一个全新的 5.4.RC4 变量而且我不确定,这个变量是否是 POST 方法的变量。
回答by Slavic
max_input_vars
is an attempt for PHP to solve some security issues and when set, it limits your number of inputs (thus, fields in your forms). Also beware of
是 PHP 解决一些安全问题的一种尝试,设置后,它会限制您的输入数量(因此,表单中的字段)。还要小心
max_input_nesting_level
And yes - they are configurable. Just edit your php.ini or htaccess values.
是的 - 它们是可配置的。只需编辑您的 php.ini 或 htaccess 值。
回答by Onyx
I too have come across this issue, working on a localised installation of my code, and Debian Sid has upgraded to 5.4 RC4 PHP. A form of over 7000 lines with checkboxes (!) suddenly only processed 1001 of these in the $_POST data...head scratching for a few hours.
我也遇到过这个问题,正在本地化安装我的代码,Debian Sid 已升级到 5.4 RC4 PHP。超过 7000 行带有复选框 (!) 的表单突然只处理了 $_POST 数据中的 1001 行......挠了几个小时。
Made the change in /etc/php5/apache2/php.ini:
在 /etc/php5/apache2/php.ini 中进行更改:
max_input_vars = 5000
save, and restart apache, and it's all good now.
保存并重新启动 apache,现在一切都很好。
回答by Ruben Benjamin
If you cannot/ do not want to increase the server limit, here is another solution
如果您不能/不想增加服务器限制,这是另一种解决方案
<!-- 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>
then using jquery
然后使用jquery
<script>
function clicked() {
var cb = $('.cbox:checked').map(function() {return this.value;}).get().join(',');
$('#cboxes').val(cb);
return true;
}
</script>
Using POST I tested posting 10000 records.
使用 POST 我测试了发布 10000 条记录。
In the server
在服务器中
$cboxes = $_POST['cboxes'];
$cbox_exp =(explode(',', $cboxes));
print_r(count($cbox_exp)); //gives me 10000
回答by Chris
Just wanted to summarize and point out a few things:
只是想总结并指出几点:
1) Limitations can be PHP as mentioned above.
1) 限制可以是如上所述的 PHP。
2) Limitations can be web server also mentioned above.
2)限制可以是上面也提到的Web服务器。
3) Suhosinlimitations only apply if it is installed. Settings are changed in php.ini
3) Suhosin限制仅在安装时适用。在 php.ini 中更改设置
4) Beware of browser URL length limits if you attempt to submit that much data in the URL
4) 如果您尝试在 URL 中提交那么多数据,请注意浏览器 URL 长度限制
Restart your web server after changing any server settings.
更改任何服务器设置后重新启动 Web 服务器。
回答by Ashesh
It's always good to just stringify some of the data you're submitting – rather than change this limit within PHP. For example, if you're sending in stuff via Ajax, or via a form field, just stringify the field that's causing the problem.
将您提交的一些数据字符串化总是好的——而不是在 PHP 中更改此限制。例如,如果您通过 Ajax 或表单字段发送内容,只需将导致问题的字段字符串化即可。
The limit is on the 'number' of fields and not the 'length', if that makes sense.
如果有意义的话,限制是字段的“数量”而不是“长度”。
回答by dots-do-matter
Apparently it looks like a patch on linux environment causing this issue. If your server has this patch 'suhosin', likely to be the issue. Also its not possible to override this in runtime rather include in your php.ini
显然,它看起来像是导致此问题的 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
回答by álvaro González
These changes tend to be well documented. Are you sure that it's been backported to 5.2? Where did you read so? It seems more likely that you are hitting some other limit such as post_max_sizeor Apache's LimitRequestFields, or even a PHP security mod like Suhosin.
这些变化往往有据可查。你确定它已经被移植到 5.2 了吗?你在哪里读的?您似乎更有可能达到其他一些限制,例如post_max_size或 Apache 的LimitRequestFields,甚至是像Suhosin这样的 PHP 安全模式。
(Furthermore, PHP 5.2 is no longer supported, so I doubt it'd receive such upgrade.)
(此外,不再支持 PHP 5.2,所以我怀疑它会收到这样的升级。)
回答by Matthew Lock
If you are using Dreamhost like me you can create a phprc file inside /home/<<siteuser>>/.php/<<X.Y>>
(siteuser = the user your site runs under, and X.Y = php version eg 7.2)
如果你像我一样使用 Dreamhost,你可以在里面创建一个 phprc 文件/home/<<siteuser>>/.php/<<X.Y>>
(siteuser = 你的网站运行的用户,XY = php 版本,例如 7.2)
Inside the phprc I added max_input_vars = 2000
在我添加的 phprc 中 max_input_vars = 2000
You must then kill all the PHP processes to take effect using killall -9 php72.cgi
if you were on PHP version 7.2
killall -9 php72.cgi
如果您使用的是 PHP 7.2 版,则必须杀死所有 PHP 进程才能生效
More info here https://help.dreamhost.com/hc/en-us/articles/214200668-How-do-I-create-a-phprc-file-via-SSH-
更多信息https://help.dreamhost.com/hc/en-us/articles/214200668-How-do-I-create-a-phprc-file-via-SSH-
回答by harpej
If you do not use multiple or more than 1000 input fields
you can be concatenating multiple inputs with any special character, for example @
如果您不使用多个或超过 1000 个输入字段,您可以将多个输入与任何特殊字符连接起来,例如 @
<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'>
using any script (JavaScript or JScript)
使用任何脚本(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
with this concept you will be bypass the max_input_vars
issue.
If you increase the max_input_vars
in php.ini
file that is harmful to server.
Because they use more server cache memory and sometimes they will crash the server.
有了这个概念,您将绕过这个max_input_vars
问题。如果增加对服务器有害的max_input_vars
inphp.ini
文件。因为它们使用更多的服务器缓存内存,有时它们会使服务器崩溃。