简体   繁体   English

PHP max_input_vars

[英]PHP max_input_vars

I'm getting a max_input_vars error message.我收到一条max_input_vars错误消息。

I understand there's a php.ini setting that can change this starting with version 5.3.9 however, I'm running version 5.1.6.我知道有一个php.ini设置可以从 5.3.9 版开始更改此设置,但是,我运行的是 5.1.6 版。

When I view the configuration information for my 5.1.6 server it shows max_input_vars value is 1000.当我查看 5.1.6 服务器的配置信息时,它显示max_input_vars值为 1000。

My question is: Even though I'm running 5.1.6, I see this setting from phpinfo() but it's not in the php.ini file.我的问题是:即使我运行的是 5.1.6,我也从phpinfo()看到了这个设置,但它不在php.ini文件中。 Does this mean that the value is hard coded in this version of PHP and can't be changed?这是否意味着该值在此版本的 PHP 中是硬编码的,无法更改?

Reference on PHP net: PHP网上参考:

http://php.net/manual/en/info.configuration.php#ini.max-input-vars http://php.net/manual/en/info.configuration.php#ini.max-input-vars

Please note, you cannot set this directive in run-time with function ini_set(name, newValue) , eg请注意,您不能在运行时使用函数ini_set(name, newValue)设置此指令,例如

ini_set('max_input_vars', 3000);

It will not work.不起作用。

As explained in documentation, this directive may only be set per directory scope, which means via .htaccess file, httpd.conf or .user.ini (since PHP 5.3).如文档中所述,此指令只能按目录范围设置,这意味着通过 .htaccess 文件、httpd.conf 或 .user.ini(自 PHP 5.3 起)。

See http://php.net/manual/en/configuration.changes.modes.phphttp://php.net/manual/en/configuration.changes.modes.php

Adding the directive into php.ini or placing following lines into .htaccess will work:将指令添加到 php.ini 或将以下行放入 .htaccess 将起作用:

php_value max_input_vars 3000
php_value suhosin.get.max_vars 3000
php_value suhosin.post.max_vars 3000
php_value suhosin.request.max_vars 3000

您可以将它添加到 php.ini 并且它应该可以工作 - 刚刚在 PHP 5.3.6 上对其进行了测试。

Have just attempted this fix with 5.3.3 and there's no change.刚刚在 5.3.3 中尝试了此修复程序,但没有任何变化。 Googling around I found this web page http://anothersysadmin.wordpress.com/2012/02/16/php-5-3-max_input_vars-and-big-forms/ detailing other settings which need changing if your server uses the Suhosin patch which Apache under Debian does.谷歌搜索我发现这个网页http://anothersysadmin.wordpress.com/2012/02/16/php-5-3-max_input_vars-and-big-forms/详细说明了如果您的服务器使用 Suhosin 补丁需要更改的其他设置Debian 下的 Apache 是做什么的。

The site explains:该网站解释说:

So, if you want to increase this number to, say, 3000 from the default number which is 1000, you have to put in your php.ini these lines:因此,如果您想将此数字从默认数字 1000 增加到 3000,则必须在 php.ini 中添加以下几行:

max_input_vars = 3000 suhosin.post.max_vars = 3000 suhosin.request.max_vars = 3000 max_input_vars = 3000 suhosin.post.max_vars = 3000 suhosin.request.max_vars = 3000

I tested it (added settings to php.ini both in /etc/php5/apache2 and /etc/php5/cli, and restarted Apache successfully) but still no max_input_vars variable in phpinfo.我测试了它(在/etc/php5/apache2和/etc/php5/cli中向php.ini添加了设置,并成功重新启动了Apache)但phpinfo中仍然没有max_input_vars变量。

A few sites point to PHP 5.3.9 as the first PHP version in which this change will take, so my fault for not RTM properly in the first place, although I'm interested to see people reporting it working in version above 5.3.3 but below 5.3.9.一些站点指出 PHP 5.3.9 作为此更改将采用的第一个 PHP 版本,所以我的错首先是 RTM 不正确,尽管我有兴趣看到人们报告它在 5.3.3 以上的版本中工作但低于 5.3.9。

It's 2018 now.And I just got stuck on this problem when I must send a request that exceeds the max_input_vars .现在是 2018 年。当我必须发送超过max_input_vars的请求时,我就陷入了这个问题。 And I came up with a solution that newie like me forgot to restart php fpm service after changing the max_input_vars param.我想出了一个解决方案,像我这样的新手在更改max_input_vars参数后忘记重新启动 php fpm 服务。 because I only tried to restart apache2 service, but not php fpm因为我只尝试重启apache2服务,而不是 php fpm

  1. uncomment code at /etc/php/7.0/fpm/php.ini and set number as you wish/etc/php/7.0/fpm/php.ini取消注释代码并根据需要设置数字
    max_input_vars = 4000
  2. restart php fpm service, as I use php 7. Therefore,重新启动 php fpm 服务,因为我使用的是 php 7。因此,
    sudo service php7.0-fpm restart

Hope it helps希望能帮助到你
Tested on Debian Stretch , php7.0Debian Stretchphp7.0上测试

您需要在 php.ini 文件中取消注释 max_input_vars 值并增加它(exp. 2000),也不要忘记重新启动您的服务器,这将有助于 99,99%。

Use of this directive mitigates the possibility of denial of service attacks which use hash collisions.使用此指令可以减少使用哈希冲突的拒绝服务攻击的可能性。 If there are more input variables than specified by this directive, an E_WARNING is issued, and further input variables are truncated from the request.如果输入变量多于此指令指定的数量,则会发出 E_WARNING,并从请求中截断更多输入变量。

I can suggest not to extend the default value which is 1000 and extend the application functionality by serialising the request or send the request by blocks.我可以建议不要扩展默认值 1000 并通过序列化请求或按块发送请求来扩展应用程序功能。 Otherwise, you can extend this to configuration needed.否则,您可以将其扩展到所需的配置。

It definitely needs to set up in the php.ini肯定需要在php.ini中设置

Note that you must put this in the file ".user.ini" in Centos7 rather than "php.ini" which used to work in Centos6.请注意,您必须将其放在 Centos7 中的“.user.ini”文件中,而不是在 Centos6 中使用的“php.ini”文件中。 You can put ".user.ini" in any subdirectory in order to affect only that directory.您可以将“.user.ini”放在任何子目录中,以便仅影响该目录。

.user.ini : .user.ini :

max_input_vars = 3000

Tested on Centos7 and PHP 5.6.33.在 Centos7 和 PHP 5.6.33 上测试。

php_value max_input_vars 6000 php_value max_input_vars 6000

"Put this line on .htaccess file of your site. " “将此行放在您网站的 .htaccess 文件中。”

Just had the same problem adding menu items to Wordpress.刚刚将菜单项添加到 Wordpress 时遇到了同样的问题。 I am using Wordpress 4.9.9 on Ubuntu 18.04, PHP 7.0.我在 Ubuntu 18.04、PHP 7.0 上使用 Wordpress 4.9.9。 I simply uncommented the following line and increased it to 1500 in /etc/php/7.0/apache2/php.ini我只是取消了以下行的注释并将其在/etc/php/7.0/apache2/php.ini增加到 1500

; How many GET/POST/COOKIE input variables may be accepted<br>
max_input_vars = 1500

Then used the following to effect the change:然后使用以下内容来实现更改:

sudo apache2ctl configtest  #(if it does not return ok Apache will not start)
sudo service apache2 reload

Hope that helps.希望有帮助。

"PHP message: PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. “PHP 消息:PHP 警告:未知:输入变量超过 1000。要增加限制更改 php.ini 中的 max_input_vars。

This php configuration parameter max_input_vars will affect not only your GET / POST / COOKIES parameters it also controls your any Form Input.这个 php 配置参数 max_input_vars 不仅会影响你的 GET / POST / COOKIES 参数,它还会控制你的任何表单输入。

To set or change its value follow the below steps.要设置或更改其值,请按照以下步骤操作。

1) check the existing setting / value by viewing it in your php.ini file Locate php.ini file by using 1) 通过在您的 php.ini 文件中查看现有设置/值来检查它使用定位 php.ini 文件

<?php echo getinfo(); ?>

find below key: Loaded Configuration File : /etc/php/5.6/fpm/php.ini找到以下键:加载的配置文件:/etc/php/5.6/fpm/php.ini

2) Open the php.ini file in editable mode and do search for max_input_vars This line may be commented in your existing default setting with default value of 1000 , So remove ; 2) 在可编辑模式下打开 php.ini 文件并搜索 max_input_vars 这行可能在你现有的默认设置中被注释,默认值为 1000 ,所以删除; to uncomment it and Edit it with your suitable value eg 2500.取消注释并使用合适的值对其进行编辑,例如 2500。

3) Save the file and Restart the Services of PHP by using below sudo service php5.6-fpm restart 3) 保存文件并使用下面的sudo service php5.6-fpm restart PHP sudo service php5.6-fpm restart

Similarly you can update any other similar PHP Configuration to your ease.同样,您可以轻松地更新任何其他类似的 PHP 配置。

Just to complement.只是为了补充。 On a shared server using mod_suphp I was having the same issue.在使用 mod_suphp 的共享服务器上,我遇到了同样的问题。

Declaring 4 max_input_vars (suhosin included), didn't solved it, it just kept truncating on 1000 vars (default), and declaring "php_value max_input_vars 6000" on .htaccess threw error 500.声明 4 个 max_input_vars(包括 suhosin),并没有解决它,它只是继续截断 1000 个变量(默认),并在 .htaccess 上声明“php_value max_input_vars 6000”抛出错误 500。

What solved it was to add the following on .htaccess, which applies the php.ini file recursively to that path解决它的是在 .htaccess 上添加以下内容,它将 php.ini 文件递归地应用于该路径

suPHP_ConfigPath /home/myuser/public_html

New Cpanels block to see the .htaccess file or if you add a .user.ini you wont be able to see it.新的 Cpanels 块可以查看 .htaccess 文件,或者如果您添加了 .user.ini,您将无法看到它。 but with a little hack you can make it work.但只要稍加修改,您就可以让它发挥作用。 Edit for example wp-config.php and in the URL bar replace wp-config.php by .htaccess now you can paste the values and save it.编辑例如 wp-config.php 并在 URL 栏中用 .htaccess 替换 wp-config.php 现在您可以粘贴值并保存它。 enter image description here在此处输入图片说明

If you are using something like wodby ( docker4php or docker4drupal ) or lando or trying to find an answer "why php.ini doesn't work" (like me), these tools are using their own way to pass configuration into php如果你正在使用类似wodby( docker4phpdocker4drupal )或兰多或试图找到“为什么php.ini中不起作用”(像我)的答案,这些工具都是用自己的方式来配置传递到PHP

https://github.com/wodby/php#php-and-php-fpm-configuration https://github.com/wodby/php#php-and-php-fpm-configuration

I was trying to set max_input_vars , in wodby+docker-compose you do it like so我试图设置max_input_vars ,在 wodby+docker-compose 你这样做

  php:
    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      PHP_MAX_INPUT_VARS: 9999

Yes, add it to the php.ini, restart apache and it should work.是的,将它添加到 php.ini,重新启动 apache,它应该可以工作。

You can test it on the fly if you want to with ini_set("max_input_vars",100)如果你想用ini_set("max_input_vars",100)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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