Big forms and PHP max_input_vars

Big forms and PHP max_input_vars

Recently I was working in WordPress to create a big menu, with over 75 links in it. When I created it and tried to save it got save only partially, few menu items at the end got truncated. I was not sure what happened. So then I tried to add 1 more link and it was not saving. Then I decided to check if there were any PHP errors. I found the following in the error logs:

PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0, referer:

Then I found out that there is a PHP setting “max_input_vars” (available since PHP 5.3.9) which limits the number of variables that PHP will process. If this value is 1000 (default is 1000) PHP will process first 1000 variables and drop the remaining. This was the reason why some menu items were saved and some not.

To solve this issue we need to increase the “max_input_vars” to a bigger number. I changed it to 2000 and it solved my problem. You might need less or more depending on your requirements.

How can we change this value? There are 2 ways. Either by changing the variable in .htaccess file or php.ini file. I will show how to change it using both the methods.

1. Change max_input_vars using .htaccess file.
If you want to change the “max_input_vars” using .htaccess file then add the following code in you .htaccess file.

php_value max_input_vars 2000

2. Change max_input_vars using php.ini file
Note: If you make any error in your php.ini file you site may not function properly. So make sure you know how to change it, else have someone who can do this change.

Edit your php.ini file and search for “max_input_vars“. this might look something similar to following:

; max_input_vars = 1000

The above line is commented, that means it will take PHP’s default value which is 1000. To change it to 2000 change that line to be:

max_input_vars = 2000

After this change you will have to restart your apache.

  1. Thank you so much! I’ve been looking for this solution like forever. You just save my life. Thanks!

  2. apache needs to be restarted? is it possible on shared hosting?

  3. I tried the .htaccess solution, but when I ran my website I got the following error:
    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    • Hi Nicholas,

      It seems there is some typo in your .htaccess file. Can you check the error logs an see what the exact error is. If you want you can contact me through my contact page with more details and we can debug why is your site giving this error.

  4. I’m using the PrestaShop CMS system for webshops. The .htaccessfiles were generated automatically when installing this CMS. My htaccess looks like this:

    SetEnv PHP_VER 5_3

    Also it seems that in every folder I have another .htaccess file… So I have no idea if I have to change the main directories’ .htaccess or if I have to change another one 🙂

    • I have not used PrestaShop CMS so I don’t know much about it. However, all the changes in .htacess file will work for the directory in which the file is and all sub-directories until there is another .htacess file inside the sub-directory. So you may or may not have to add it to every file.

      However if the file is auto generated I would recommend adding it to the place from where it generates it so that the changes are not lost when the file is generated again.

  5. + I only get the Internal server error when I add php_value max_input_vars 2000

    • What server are you using? I had tested this on different versions of apache and php and it worked fine. Can you let me know your apache and php versions so that I can try to reproduce the issue and see how we can fix it.

  6. Hello, add the command
    ;How many GET / POST / COOKIE input variables May be accepted
    then max_input_vars = 99999 just after max_input_nesting_level = 64 in the php.ini file because the . htaccess file if you have activated the url rewriting you erase the line max_input_vars = 99999 each time

    • I am not sure how to add this code can you clarify as how and where to add it? Are you saying make changes to Both .htaccess AND php.ini?

      should it look like this in the php.ini? ONLY this?
      max_input_vars = 99999
      max_input_nesting_level = 64

      Do I add anything to the .htaccess file?

      Is a restart required?

  7. Thanks a lot. This saved my time. I’ve been bumped into this issue while working with huge drupal menu form > 400 items.

  8. hi, I have the same issue – but in my case max_input_vars = 7000; does nothing…
    info.php shows the value 7000, I did apachi reboot – but still can’t put more then 90 items on my wordpress menu…

    do you have any soloution?

  9. I am having the same problem of menu dropping errors when Avada WP Theme added megamenu capability. BUT I am NOT getting the this error:

    PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0, referer:

    I am showing no php warning related to max_input_vars in my error log.

    I did try your suggestions anyway. When I tried the .htaccess change, I too received a 500 internal server error code. I had already done the php.ini changes but I have not restarted the server. But my phpinfo.php page does show the changes in max_input_vars. So why is a restart required?

    Cpanel 11.38.2
    Apache 2.2.26
    My SQL 5.5.32

  10. thank you very much!

  11. Due to php.ini not modifiable I tried to write the above mentioned line in htaccess but I obtain only an “Internal server error – error 500” because this line “php_value max_input_vars 2000” results wrong….
    What can I do to fix it??

  12. First way is worked for me.

Leave a Reply