Hello, I met the code
$ body = file_get_contents ('php: // input');
Is this method needed to get the contents of POST and GET requests? What has $ _POST and $ _GEt not satisfied with?
Why do we need this horror at all?
Reading the article it is difficult to enter what these flows are for … No examples, no sensible presentation …
Answer 1, authority 100%
what is wrong with the manual?
original:
php: // input is a read-only stream
translation:
php: // input is a stream only
for reading
original:
php: // input instead of
$ HTTP_RAW_POST_DATA as it does not
depend on special php.ini directives.
Moreover, for those cases where
$ HTTP_RAW_POST_DATA is not populated
by default, it is a potentially less
memory intensive alternative to
activating
always_populate_raw_post_data.
translation:
In case of POST requests
it is preferable to use
php: // input instead of
$ HTTP_RAW_POST_DATA since this
method does not depend on special
php.ini directives. In addition, in those
cases where $ HTTP_RAW_POST_DATA is not
is filled in by default, this
potentially less costly for
memory than activation directive
always_populate_raw_post_data.
original:
php: // input is not available with
enctype = “multipart / form-data”
translation:
php: // input is not available with type
content
enctype = “multipart / form-data”
Answer 2, authority 94%
For example, you need to send json a serialized string.
You need to transfer this via POST, because in GET the length of this very line is limited, it seems, by 4 kilobytes.
What exactly is passed by the POST method?
And this is what is transmitted:
POST /test/script.php HTTP / 1.1
Host: site.com
Content-Length: xxxx
... and other headers ..
paramName1 = paramValue1 & amp; paramName2 = paramValue2 ...
I don’t want to transmit something like: abc = & lt; json_string & gt;
, because you also need to escape this string.
So we just feed the string to the script. Something like this will come to the server:
POST /test/script.php HTTP / 1.1
Host: site.com
Content-Length: xxxx
... and other headers ..
{"paramName1": "paramValue2", "paramName2": "paramValue2", ...}
Naturally, the server cannot parse such requests, so file_get_contents ('php: // input');
We can get what was sent to us without changes, parse it ourselves and be happy 🙂
Answer 3, authority 10%
The list of methods is not limited to GET and POST. For example, REST specifications also use PUT, DELETE, and some others. They are processed accordingly via php: // input.
And the meaning is simple, we get a raw request in this way, a very useful thing.