HTML & PHP input[] <- array ? Limitations
It's more of a wether can someone confirm my theory, as for going short ways, when you add another input
which shall have similar name ex. myvar_0
, myvar_1
you are supposed to use javascript
to generate tho开发者_如何学编程se inputs
, but there is input "array" type
, where you crate an input
with name myvar[]
, myvar[]
, myvar[]
and this acts as an array
and passes values via post
to PHP as an array
, but recently i've discovered that for some weird reason this array
has limitation of 197 values
( or 196 is the maximum capable index value ) as on chrome
for now ( didn't text it on other browser ).
So does anyone else encoutered a similar problem ?
If you're using suhosin
, that brings a limit to the max_vars
sent via POST.
Default is set to 200, so could be your problem.
See: suhosin.post.max_vars
array format got nothing to do with html or browser , for browser square brackets doesn't mean any special thing it will send all the key , value pairs with same key as opt[] e.x
for
<input type="hidden name="opt[]" value="1"/>
<input type="hidden name="opt[]" value="2"/>
<input type="hidden name="opt[]" value="3"/>
browser will send
opt[]=1
opt[] =2
opt[]=3
as a request to the server;
Its the PHP which is smart enough to interpret this as index array with name of "opt" .
I've just done a simple test (See below) which returns (for me) 200 items in a post array.
<form method="post">
<?php
print count($_POST['opt']);
for($i = 0; $i < 200; $i++){
?><input type="hidden" name="opt[]" value="1" /><?php
}
?>
<input type="submit" />
</form>
I get the impression this is more about the data being sent, or the server itself, than a limitation of PHP.
Well the answer was the Suhoshin security module, after some research i found that acually max_post_vars was set to 200, that was kinda blocking the rest of data from being processed, thanks for all your answer :-)
精彩评论