30

Can I set the max_input_vars PHP.ini directive in my code? I have it set at the default 1000, however I have a script that has many checkboxes and text fields that could, and quite possibly will, go over the 1000 limit.

I'm using PHP 5.3.10 and i'm not getting any errors doing this. Also, I can't find any documentation that states I can't do this.

ini_set('max_input_vars', 3000);

Thanks.

2
  • 2
    Possible duplicate of PHP max_input_vars Commented Dec 21, 2015 at 18:40
  • It it doesn't work then you can put following in your .htaccess file: php_value max_input_vars 5000
    – Umar Niazi
    Commented Apr 20, 2019 at 6:42

2 Answers 2

68

max_input_vars has a changeable mode of PHP_INI_PERDIR meaning it can't be changed using ini_set (only in php.ini, .htaccess or httpd.conf)

5
  • 12
    And the main reason is that the directive has already taken effect when the PHP code starts running. Commented Apr 2, 2012 at 9:29
  • 8
    For future readers add to your .htaccess: php_value max_input_vars 3000 Commented Dec 8, 2012 at 20:15
  • @MichaelCalkins is it possible to make php_value max_input_vars 3000 in .htaccess to work only for one php file and not for all?
    – AldoB
    Commented Mar 20, 2013 at 11:47
  • @Michael: If you read the above, you will see that using ini_set won't work
    – Bjorn
    Commented Mar 24, 2013 at 10:01
  • 1
    It works in .htaccess like this: php_value max_input_vars 10000
    – Umar Niazi
    Commented Apr 20, 2019 at 6:42
11

I know many people avoid accessing php.ini due to one reason or the other. so another way would be to create a .htaccess file in the operation folder and add the following codes and set the values to a higher value. Just add them directly no need to initialize anything in the .htaccess file

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

This solution worked for me without accessing the php.ini file. since some of the web host providers give us a hard time when we want to access the php.ini file

1
  • 1
    I like this solution better than the accepted answer, because you can localize the change to a specific domain / subdomain (if you have multiple on your server) and a specific directory within that domain (for example, /api or /ajax, or some other). Commented Feb 23, 2023 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.