14 September 2017

php://input

Actually php://input allows you to read raw POST data.

php://input is not available with enctype="multipart/form-data".





So, if you simply POST a good old HTML form, the request looks something like this:
POST /page.php HTTP/1.1

key1=value1&key2=value2&key3=value3



request with a JSON-payload would look something like this:
POST /page.php HTTP/1.1

{"key1":"value1","key2":"value2","key3":"value3"}
The content would now be application/json (or at least none of the above mentioned), so PHP's $_POST-wrapper doesn't know how to handle that (yet).
The data is still there, you just can't access it through the wrapper($_POST). So you need to fetch it yourself in raw format with file_get_contents('php://input') (as long as it's not multipart/form-data-encoded).




ref:  https://stackoverflow.com/questions/8893574/php-php-input-vs-post

No comments:

Post a Comment

Terima kasih