Search code examples
phppostwarningsslim

How to determine that POST method more than 1000 variables by PHP default?


I have a table with multiple inputs in separate forms which would like each user has 15 from inputs to be passed. In this case I have around 80 users in the table and I have to post all the form inputs at once to the server site.

However, I received PHP warnings about receive more than 1000 input variables and suggest to increase the max cap for the input variables length. I only receive around 75 users form inputs in this case. The form inputs are passed through jQuery method .serialize()

I wonder how to calculate the input variables count in php... I've tried to use count($request->getParams()) and it returns 15 (outer layer keys count) which my returning variables is in this way:

name => array (
    [0] => john
    ....
    [79] => Serene
),
age => array (
    [0] => 21,
    ....
    [79] => 24,
),
....

In this case, is the variable count in 15 keys times with 80 key-value pair which is 1200 variables in total? Is this the way that PHP to calculate the input variables by calculate all the incoming form inputs?

I know how to count multidimensional array but I just wonder that the PHP whether it determine the input variables length by counting the outer layer keys count or all the keys in the input variables?

(p.s. the table has to post all user information form input due to the design of the code)


Solution

  • You mean count($_POST, true) ?

    count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )

    mode

    If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array.

    I suppose this is more proper:

    count($_POST, COUNT_RECURSIVE)
    

    Special attention to recursively count the array

    Of course by the time you can count them you may have already exceeded the limit, which is for HashDos (array hash table collision attacks).

    I watched a good webinar by the Boss man "Rasmus Lerdorf" (the guy that invented PHP) a few years ago now on it ( on HashDos not counting arrays ... lol ).

    *PS - if you didn't know count could take 2 arguments, I won't say how long it took me to figure that one out....