Php – Undefined variable: HTTP_RAW_POST_DATA


when I do a simple echo of $HTTP_RAW_POST_DATA i get the error:

Undefined variable: HTTP_RAW_POST_DATA

I read that in php.ini i need to un-tick

always_populate_raw_post_data = On

but i still get the error and I did restart Apache as well. Im using php 5.3.6

Best Solution

If you need to access the raw POST body you should really favor the use of the php://input stream over $HTTP_RAW_POST_DATA as per the relevant manual entry:

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use 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. php://input is not available with enctype="multipart/form-data".

So, to access the POST body using php://input:

$post = file_get_contents('php://input');