Php post vars limit

How to Increase PHP Max Input Vars Limit in WordPress

The “PHP Max Input Vars” variable max_input_vars was introduced in PHP as a security measure to limit the maximum number of POST variables sent. It represents the number of variables your server can use to run a function.

If you get the error “Increase PHP Max Input Vars Limit” in WordPress, you must increase the PHP max_input_vars value.

This post explains how to change the maximum number of PHP script input variables for your web hosting account to meet specific application needs.

This error can cause non-specific issues like losing all theme settings, or the widgets may disappear when the WordPress settings are saved. Also, other plugins may stop working or not work as expected anymore.

There are many different methods to increase PHP Max Input Vars in WordPress. However, this entirely depends on the hosting provider you are using.

Читайте также:  Питон для начинающих знаки

Remember that you may not have specific permissions to increase the maximum PHP input variable limit. Therefore, contact your hosting provider beforehand and ask them to grant you the necessary permissions.

How to Increase PHP Max Input Vars Limit?

You can increase the PHP Max Input Vars Limit by adding lines to the .htaccess file, php.ini, or wp-config.php.

Here we explain all methods.

Edit the .htaccess File.

The first method to increase the Max input var limitation is editing the .htaccess file. Before making any changes to the file, ensure you get a backup of your site or at least of this file.

Usually, this file is in the root directory of your host. Open the file with your file manager or FTP client.

Increase Max Input Vars in .htaccess

It could be because most hosting providers hide the (.) files if you can’t locate it. Therefore, look for the option Show Hidden Files in your file editor and enable it.

Open the .htaccess file in an editor and add the following code to it:

php_value max_input_vars 2000

If you are using Suhosin, add the following to the file instead:

php_value suhosin.request.max_vars 2000
php_value suhosin.post.max_vars 2000

The recommended value is 2000 for PHP input vars. If you need more, you could always increase it to match your needs.

Edit the PHP.ini File.

The following method to increase the PHP max input vars limit in WordPress is editing the php.ini file.

This file is also in the root directory of your host, where you have installed WordPress.
If you can’t find it, create a new empty php.ini file.

In either case, open the file in an editor and add the following code to it:

Don’t forget to save the changes and reboot your server once to use the newly added data.

Edit the wp-config.php File.

This method requires you to log in to your hosting panel or FTP.
Go to File Manager and look for the wp-config.php file.

Open the file in an editor and add the following code to it:

@ini_set( ‘max_input_vars’ , 2000 );

You can replace 2000 with any value you require. However, we recommend 2000 or higher.
If you use any value below 2000, it could throw the Max Input Vars error.

How to Increase the Max Input Vars Limit in PHP5?

If you use a host that still uses PHP5, like GoDaddy or Bluehost, you need to edit php5.ini and user.ini files.

So, if you use a host that still uses PHP5, you need to create the files mentioned above. After creating them, copy and paste the following code to both:

max_input_vars = 2000
suhosin.get.max_vars = 2000
suhosin.post.max_vars = 2000
suhosin.request.max_vars = 2000

Again, you can replace 2000 with the value your website needs.

However, if your host still uses PHP5, you should immediately contact them to update that PHP version as it is not supported anymore. At the time of writing of this article, the latest version is PHP 8.2.6. That’s a recommended PHP version.

Possible Server-Side Issues

If you tried each of the methods above and still get the max input vars error, you need to contact the hosting provider and ask them to fix the issue.

For instance, another copy of the php.ini file in the host could overwrite your local settings.

This article explained every possible method to increase WordPress’s PHP max input vars limit. Follow the steps above only if you are familiar with working with server files. Otherwise, contact your hosting provider, ask them to help you, or contact our support team.

Источник

Установка лимитов PHP на обработку данных из форм

Перечень настроек PHP, которые могут ограничить отправку форм и файлов через POST-запрос.

Описание директив

post_max_size

Устанавливает максимальный размер данных, отправленных методом POST, включая размер загружаемых файлов, по умолчанию 8Mb .

  • Для загрузки больших файлов это значение должно быть больше значения upload_max_filesize.
  • Значение можно указать числом в байтах, K (в килобайтах), M (в мегабайтах) и G (в гигабайтах).
  • Значение «0» снимает ограничение только в версиях PHP 5.3.2 и 5.2.12.

Пример в htaccess:

php_value post_max_size 100M

upload_max_filesize

Максимальный размер загружаемых файлов на сервер. По умолчанию 2Mb.

Пример:

php_value upload_max_filesize 100M

max_input_vars

Максимальное количество переменных, которое может быть принято в одном запросе. По умолчанию 1000.

Если данный лимит будет превышен, то после отправки формы массив $_GET или $_POST будет пустым.

Пример:

php_value max_input_vars 2000

max_execution_time

Директива задаёт максимальное время в секундах, в течение которого скрипт должен полностью загрузиться. Если этого не происходит, работа скрипта завершается. По умолчанию на загрузку даётся 30 секунд.

Значение «0» снимает ограничение на время выполнения.

Пример:

php_value max_execution_time 600

Также, максимальное время выполнения скрипта задает функция set_time_limit($seconds) .

max_input_time

Задаёт максимальное время в секундах, в течение которого скрипт должен разобрать все входные POST или GET данные. Это время измеряется от момента, когда PHP вызван на сервере до момента, когда скрипт начинает выполняться.

  • Значение по умолчанию «-1» – будет использоваться max_execution_time.
  • Значение «0» – без ограничений по времени.

Пример:

php_value max_input_time 600

memory_limit

Задаёт максимальный объем памяти в байтах, который разрешается использовать скрипту. По умолчанию 128Mb.

Пример:

php_value memory_limit 200M

Установка директив в .htaccess

# Максимальный размер данных php_value post_max_size 110M # Максимальный размер файлов php_value upload_max_filesize 100M # Максимальное количество переменных php_value max_input_vars 2000 # Максимальное время выполнения скрипта php_value max_execution_time 600 # Максимальное время обработки данных php_value max_input_time 600 # Память для скрипта php_value memory_limit 200M 

Установка директив в PHP-скрипте

ini_set('post_max_size', '110M'); // Максимальный размер данных ini_set('upload_max_filesize', '100M'); // Максимальный размер файлов ini_set('max_input_vars', '2000'); // Максимальное количество переменных ini_set('max_execution_time', '600'); // Максимальное время выполнения скрипта ini_set('max_input_time', '600'); // Максимальное время обработки данных ini_set('memory_limit', '200M'); // Память для скрипта

Получение значений в PHP-скрипте

Действующие значения настроек PHP можно посмотреть с помощью функции phpinfo() или получить значение параметра настройки с помощью функции ini_get($option) .

Получение значения upload_max_filesize в PHP:

'; echo 'Максимальный размер файлов: ' . ini_get('upload_max_filesize') . '
'; echo 'Максимальное количество переменных: ' . ini_get('max_input_vars') . '
'; echo 'Максимальное время выполнения скрипта: ' . ini_get('max_execution_time') . '
'; echo 'Максимальное время обработки данных: ' . ini_get('max_input_time') . '
'; echo 'Память для скрипта: ' . ini_get('memory_limit') . '
';

Результат:

Максимальный размер данных: 128M Максимальный размер файлов: 128M Максимальное количество переменных: 10000 Максимальное время выполнения скрипта: 300 Максимальное время обработки данных: -1 Память для скрипта: 1024M

Возможные ошибки

После отправки формы с множеством полей, массив $_POST пустой.
В форме количество полей превышает значение max_input_vars.

Ошибка «Fatal error: Allowed memory size»
Скрипт превысил значение параметра PHP memory_limit.

Ошибка «504 Gateway Time Out»
– Скрипт выполняется слишком долго, нужно увеличить значение max_execution_time. Как правило после вывода этой ошибки в браузере, скрипт будет еще какое-то время работать.

Источник

Increase PHP post variable limits

In some cases, you will need to post a lot of variables. Under some circumstances, some server side or PHP settings will block you from sending too much variables over post data.

It is easy to overcome this. Just read on.

Determining the cause:

There are two ways PHP will block long and numerous post variables, suhosin security module and generic php.ini settings. In both the cases, you’d need to upload a file named phpinfo.php to your server with following code inside:

http://domain.com/phpinfo.php and search for (Simple Ctrl + F), suhosin . If you find something like

This server is protected with the Suhosin Patch 0.9.10

then your server has suhosin installed.

php-suhosin

Otherwise, it is limited by generic php.ini settings.

Solutions:

Depending on the cause, the solution will vary. But both of them require editing your php.ini file. Check this tutorial to learn how to.

Increasing suhosin variable:

Edit the following variables and put the values as given below:

suhosin.request.max_vars = 2048 suhosin.request.max_value_length = 1000000 suhosin.request.max_array_index_length = 256 suhosin.request.max_totalname_length = 8192 suhosin.post.max_vars = 2048 suhosin.post.max_array_index_length = 256 suhosin.post.max_totalname_length = 8192 suhosin.post.max_value_length = 1000000 suhosin.sql.bailout_on_error = Off suhosin.log.file = 0 suhosin.log.phpscript = 0 suhosin.log.phpscript.is_safe = Off suhosin.log.sapi = 0 suhosin.log.script = 0 suhosin.log.use-x-forwarded-for = Off

If you do not have access to your php.ini file, then you can try doing it by adding the following code to the .htaccess file on the root of your server.

 php_value suhosin.request.max_vars 2048 php_value suhosin.request.max_value_length 1000000 php_value suhosin.request.max_array_index_length 256 php_value suhosin.request.max_totalname_length 8192 php_value suhosin.post.max_vars 2048 php_value suhosin.post.max_array_index_length 256 php_value suhosin.post.max_totalname_length 8192 php_value suhosin.post.max_value_length 1000000 php_flag suhosin.sql.bailout_on_error Off php_value suhosin.log.file 0 php_value suhosin.log.phpscript 0 php_flag suhosin.log.phpscript.is_safe Off php_value suhosin.log.sapi 0 php_value suhosin.log.script 0 php_flag suhosin.log.use-x-forwarded-for Off 

Increasing generic php.ini value:

php-post-var-limit

Edit the following variable and put the value as given below

max_input_vars = 20480 post_max_size = 32M

If all of the methods fail, then you’d need to ask your web host. Sometimes, these variables are also blocked by server side firewalls.

Share this:

9 people found this article useful This article was helpful

9 people found this article useful

Swashata has written 257 articles

Hi there, I am the Lead Developer at WPQuark.com. I love to create something beautiful for WordPress and here I write about how to use them. When I am not working, usually I am doing a number of other creative things ;).

Источник

Оцените статью