5

Is there any way to increase the PHP max_input_vars limit for only one PHP page. I'm using a CSV upload and extract function. In which the csv data will be saved to the db using Insert query. But when i tried with larger CSV data such as about 9000 entries i got an error like this:

PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini.

I know we need to change the limit value in php.ini or .htaccess but i don't want to change the limit for the entire project for maintaing the security. So Is there any way to change it only for this functionality ??

Zammuuz
  • 708
  • 4
  • 18
  • 43
  • If you're using a CSV formatted file, why not use [`LOAD DATA`](http://dev.mysql.com/doc/refman/5.7/en/load-data.html) to import it? That's way less messy than a gigantic statement. – tadman Jul 25 '16 at 03:36

1 Answers1

3

There's no way of doing that. You have to change it in the php.ini file, because not even ini_set can change it.

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)

(Source)

You can, however, temporarily change that setting by adding this line to your .htaccess:

php_value max_input_vars 3000

(Source)

Community
  • 1
  • 1
Martin
  • 1,065
  • 8
  • 13
  • Martin S.: Okay. Actually i'm a bit confused about this input vars. I got this error when the multi select dropdown contains almost 9000 entries. but on Post we are passing the select option values as array to one input element right?? which is the select element name. Can you please describe about what this max_input_vars limit is for?? Is it the number of input elements that can be passed through POST ? if it is then why my select dropdown shows that error?? – Zammuuz Jul 26 '16 at 08:04
  • @USER5615 it is the amount of variables allowed in each superglobal. I can't know why you get that error if you don't show me your code, but I guess you're passing way too much variables via POST. – Martin Jul 27 '16 at 02:53
  • 1
    The reason that a big multi-select causes this problem is that each selected option is passed as `fieldname[]=value`. Note how this looks almost like a separate form field. While parsing the data and loading it into vars, this gets treated as an array, but it still counts each assignment as one "input var". – PaulC Nov 02 '16 at 21:20