25

I was wondering if anybody knows the total length that a post global could be. e.g:

$_POST['formInput'] = "hello world, how long can I be?";

I am creating a site where someone will enter an unknown amount of chars into a textarea, so potentially it could be 2 pages on a word document.

So if anybody knows of any other methods of how I can do this apart from using a $_POST global (it can't be saved in a file, as it's important data that I don't want other people to find) - that would be very helpful.

Thanks

informatik01
  • 16,038
  • 10
  • 74
  • 104
phpNutt
  • 1,529
  • 7
  • 23
  • 40
  • 1
    possible duplicate of [What is the size limit of a post request?](http://stackoverflow.com/questions/2364840/what-is-the-size-limit-of-a-post-request) this is older by a month, but the other is better posed IMHO – Ciro Santilli OurBigBook.com Nov 10 '14 at 08:00
  • This directive specifies the number of bytes from 0 (meaning unlimited) to 2147483647 (2GB) that are allowed in a request body. http://httpd.apache.org/docs/2.0/mod/core.html#limitrequestbody – Anja Ishmukhametova May 19 '20 at 01:46

4 Answers4

29

Check your php.ini for post_max_size. This is typically about 8mb by default, but if you're on shared-hosting, it could definitely vary.

; Maximum size of POST data that PHP will accept.
post_max_size = 8M

You'll have to use $_POST if you wish to send large amounts of data to the server. For further study, I'd suggest checking out POST Method Uploads in the documentation.

Sampson
  • 265,109
  • 74
  • 539
  • 565
  • 12
    Apache has the LimitRequestBody & LimitRequestFieldSize directives too, not always safe to assume it's restricted by just PHP. – tadamson Feb 16 '10 at 22:33
9

$_POST is populated from the body of a HTTP-request. Since there are no restrictions on the size of a HTTP-request, there are no restrictions in the protocol layer. However PHP has some limitations on how much input it will read. You can control this with the ini-setting post_max_size

troelskn
  • 115,121
  • 27
  • 131
  • 155
4

Another problem can be the default limit in php.ini for directive max_input_vars (default 1000), not only the post_max_size. If you have e.g. a very large form with thousands of checkboxes the $_POST array will have only 1000 keys.

Petr Novotny
  • 198
  • 2
  • 6
  • 1
    This actually solved my problem with a request being a lot less than `post_max_size`, but it hit the `max_input_vars` limit. Thanks! – themarketka Aug 28 '14 at 13:45
  • 1
    Man you saved my day. I only posted about 80kb of data but with > 1000 fields (big form). Arbitrary fields seemed to be missing on side of PHP until I checked what the browser initially posted against what $_POST[] actually contained, and realized that "only" 1000 fields where parsed. – flu Sep 25 '15 at 09:24
1

If you want some large amount of data sent from the browser to the server, you'll have to use HTTP POST method -- which means the data will be received, on the PHP side, in the $_POST superglobal array ; there's not much you can do about that.

The configuration directive post_max_size defines the maximum amount of data that can be received using the POST method -- you might need to set that to a value higher than the default one, depending on your needs.

And, as said on the documentation of post_max_size, the value set for memory_limit can also have its importance.

Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663