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:

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

    Code (Text):
    1.  
    2. for ($i=0; $i < count($_POST['example']); $i++){
    3.     $form_example[$i] = $_POST['example'][$i];
    4. }
    5.  
    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...

    Code (Text):
    1.  
    2. <?
    3. // TEST to find the limit of POST array data...
    4.  
    5. // Try increasing/decreasing these two values:
    6. $num_rows = 50;
    7. $num_arrays = 10;
    8.  
    9. $exampledata = 1;
    10.  
    11. for ($i=0; $i < count($_POST['example_1']); $i++){
    12.     for ($a=1; $a <= $num_arrays; $a++){
    13.         ${"example_".$a}[$i] = $_POST['example_'.$a][$i];
    14.     }
    15. }
    16.  
    17. ?>
    18.  
    19. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    20. <html xmlns="http://www.w3.org/1999/xhtml">
    21. <head>
    22. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    23. <title>POST LIMIT TEST</title>
    24. </head>
    25. <body>
    26.  
    27. <?
    28. $buttonvalue = $_POST['submit'];
    29. echo "Button value: ".$buttonvalue."<br />";
    30. echo "Array value: ".$example_1[0]."<br />";
    31. ?>
    32. <form id="POST_test" method="post" action="">
    33.  
    34. <table>
    35. <? for ($r=0; $r < $num_rows; $r++){ ?>
    36.     <tr>
    37.     <? for ($a=1; $a <= $num_arrays; $a++){ ?>
    38.         <td><input name="example_<? echo $a ?>[]" type="text" value="<? echo $exampledata; ?>" size="3" maxlength="3"  /></td>
    39.     <? } ?>
    40.     </tr>
    41. <? } ?>
    42. </table>
    43.  
    44.     <input type="submit" name="submit" id="submit" value="Submit" />
    45.  
    46. </form>
    47.  
    48. </body>
    49. </html>
    50.  
    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
    PHP:
    1. ini_set('post_max_size', '32M');
    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