0

Supposed I'm receiving an HTTP request. I try to access it, but because it has lots and lots of data, PHP's max_input_vars directive effectively cuts some of the parameters from request: When I try to access the request using e.g. $_REQUEST, some of the data is missing. How do I know when this happens?

For some background:

I know I can get count($_REQUEST) and compare it to the value returned by ini_get('max_input_vars'), but I would like to write foolproof code where I can detect exceeding the limit by even one. Another drawback of this method is that when passing lists etc., each list element becomes a separate request parameter that counts towards the limit, but PHP parses them into a single array again. For example, something like list = [1, 2, 3] is passed as something like this in the request:

list[]=1
list[]=2
list[]=3

After PHP parses this into, say, $_REQUEST, it's a single array (i.e. $_REQUEST['list']) again, which causes count($_REQUEST) to not return the wanted value. It's possible to get around this but it's not the most convenient thing to do.

Xiyng
  • 327
  • 1
  • 5
  • 16
  • Just for the record: I have a work-around where I manually compute the number of items in both ends and pass the number as one of the parameters. It's fairly hacky though, and I was curious if there might be a better way. – Xiyng Jun 01 '18 at 14:35

1 Answers1

0

http://php.net/manual/en/info.configuration.php#ini.max-input-vars

If there are more input variables than specified by this directive, an E_WARNING is issued...

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Ah, I forgot to mention it but that part is clear. I would like to do this in code so I can react to the situation, preferably to respond with an error of some sort. As it is, this is of course a perfectly valid answer. – Xiyng Jun 01 '18 at 14:33
  • 1
    @Xiyng Check https://stackoverflow.com/questions/1241728/can-i-try-catch-a-warning for strategies for that. It's entirely possible to catch and act on an `E_WARNING`. – ceejayoz Jun 01 '18 at 14:35
  • Ooh, that's neat! – Xiyng Jun 01 '18 at 14:36