1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP form POST data limit?

Discussion in 'PHP' started by downpour, Sep 28, 2009.

  1. #1
    Hi everyone,

    I've got an annoying problem with a form I'm working on.

    Basically it's a table of data with some cells containing text input boxes, all named something like this:

    <input name="example[]" type="text" value="<? echo $exampledata; ?>"  />
    Code (markup):
    This puts all the values into an array (example[]), I then retrieve them with:

    
    for ($i=0; $i < count($_POST['example']); $i++){ 
    	$form_example[$i] = $_POST['example'][$i]; 
    }
    
    Code (markup):
    There are a few text input arrays like this and an array of hidden input fields to relate one lot of data to another...

    All of this works fine...

    ...Until I get too many rows in the table. Then the POST data just STOPS being received by my script. Even the submit button doesn't send anything back.

    I'm not even talking about a lot of data here. There are 13 arrays in total but they only hold the numbers 0-9. It falls over when they contain about 30 records...

    So does anyone know the maximum amount of data a form can contain? Am I just going over the limit?:confused:
     
    downpour, Sep 28, 2009 IP
  2. sunchiqua

    sunchiqua Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You must be doing something wrong - as far as I know, there's no limit ( at least I haven't spotted one in the past 5 years ).
     
    sunchiqua, Sep 28, 2009 IP
  3. downpour

    downpour Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK I just put this together to test my theory, please try it out if you can.
    I find if I have the $num_rows set to 50 and $num_arrays at 10 it doesn't work, but if I drop them down to say 10 and 4, then it works fine...

    
    <?
    // TEST to find the limit of POST array data...
    
    // Try increasing/decreasing these two values:
    $num_rows = 50;
    $num_arrays = 10;
    
    $exampledata = 1;
    
    for ($i=0; $i < count($_POST['example_1']); $i++){ 
    	for ($a=1; $a <= $num_arrays; $a++){ 
    		${"example_".$a}[$i] = $_POST['example_'.$a][$i]; 
    	}
    }
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>POST LIMIT TEST</title>
    </head>
    <body>
    
    <? 
    $buttonvalue = $_POST['submit'];
    echo "Button value: ".$buttonvalue."<br />";
    echo "Array value: ".$example_1[0]."<br />";
    ?>
    <form id="POST_test" method="post" action="">
    
    <table>
    <? for ($r=0; $r < $num_rows; $r++){ ?>
    	<tr>
    	<? for ($a=1; $a <= $num_arrays; $a++){ ?>
    		<td><input name="example_<? echo $a ?>[]" type="text" value="<? echo $exampledata; ?>" size="3" maxlength="3"  /></td>
    	<? } ?>
    	</tr>
    <? } ?>
    </table>
    
    	<input type="submit" name="submit" id="submit" value="Submit" />
    
    </form>
    
    </body>
    </html>
    
    Code (markup):
    Please let me know if it is the same with your server...
     
    downpour, Sep 28, 2009 IP
  4. downpour

    downpour Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    From experimentation it seems that if you use any more than 200 array values the POST data (after that point) is lost.

    So I could have 10 arrays of 20 values or 1 array of 200 values but any more than that and the data starts to get lost. :mad:
     
    downpour, Sep 28, 2009 IP
  5. sunchiqua

    sunchiqua Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ini_set('post_max_size', '32M');
    PHP:
    Additionally, take a look at upload_max_filesize.
     
    sunchiqua, Sep 28, 2009 IP
  6. downpour

    downpour Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks, I've found the problem. Suhosin is installed on the server I'm using and it is setting the limit. For anyone else having this problem you need to add this to your php.ini file.

    php_value suhosin.request.max_vars 2048
    php_value suhosin.post.max_vars 2048
     
    downpour, Sep 28, 2009 IP
  7. lhoezee

    lhoezee Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    downpour,

    Even though it's been about 2 years since you resolved this issue. I had to register for an account here to say thank you for posting the solution! I thought I was going crazy!!!

    Luke
     
    lhoezee, Mar 31, 2011 IP
  8. lhoezee

    lhoezee Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Actually ... let me correct something really quick...

    I think doing it this way is for .htaccess?
    php_value suhosin.request.max_vars 2048
    php_value suhosin.post.max_vars 2048

    I had to do this for my php.ini file to make it work:
    suhosin.request.max_vars = 2048
    suhosin.post.max_vars = 2048

    Thanks again for pointing me in the right direction.
     
    lhoezee, Mar 31, 2011 IP