$_POST vs. $HTTP_RAW_POST_DATA vs file_get_contents(php://input)?

php

Solution

- $_POST contains URL encoded (application/www-url-encoded) variables that are posted to your script and PHP decodes them for you. You use this one when you deal with HTML FORM data.

- file_get_contents("php://input") - gets the raw POST data and you need to use this when you write APIs and need XML/JSON/... input that cannot be decoded to $_POST by PHP.

- $HTTP_RAW_POST_DATA - in theory it is the same as the above but depends on php.ini. (DEPRECATED, SEE COMMENT)

I always use method #2 instead of #3 when I need non application/www-url-encoded input.

Problem

Possible Duplicate: What’s the difference between POST and raw POST in PHP at all? For a better understanding, I would be grateful if you would explain what are the fundamental differences between $_POST, $HTTP_RAW_POST_DATA and file_get_contents(php://input). When to use which, and why?

Original source

Related problems