Changing the max_input_vars directive in PHP scripts
The max_input_vars directive in PHP controls the maximum number of input variables your script can handle. By default, this value is set to 1000. If your application (such as WordPress, Joomla, or a custom CMS) uses large forms or complex data structures, you may need to increase this limit to avoid errors like:
Warning: Unknown: Input variables exceeded 1000.To increase the limit change max_input_vars in php.ini.Why Adjust max_input_vars?
Section titled “Why Adjust max_input_vars?”- Large forms with many fields (e.g., product catalogs, survey forms).
- Complex CMS configurations with nested arrays.
- Prevents data loss when submitting forms with more than 1000 fields.
Methods to Change max_input_vars
Section titled “Methods to Change max_input_vars”1. Using a Custom php.ini File
Section titled “1. Using a Custom php.ini File”Create or edit a php.ini file in your application directory:
max_input_vars = 15002. Using .user.ini
Section titled “2. Using .user.ini”If your hosting environment supports .user.ini files:
max_input_vars = 1500Place this file in the root directory of your application.
3. Using .htaccess
Section titled “3. Using .htaccess”On Apache servers, you can override the directive in .htaccess:
php_value max_input_vars 15004. Using cPanel (CageFS Enabled Accounts)
Section titled “4. Using cPanel (CageFS Enabled Accounts)”- Log in to cPanel.
- Go to Software → Select PHP Version → Options tab.
- Locate
max_input_vars. - Increase the value (e.g., 1500 or 2000).
- Save changes.
Verification
Section titled “Verification”-
Create a test file
info.phpwith:<?php phpinfo(); ?> -
Visit
http://yourdomain.com/info.php. -
Search for
max_input_varsin the output to confirm the new value. -
Delete the file afterward for security.
Best Practices
Section titled “Best Practices”- Increase gradually (e.g., 1500 → 2000) instead of setting excessively high values.
- Monitor memory usage, as higher limits can increase resource consumption.
- Always test form submissions after making changes.