Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined variable: HTTP_RAW_POST_DATA

Tags:

php

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

like image 619
Exploit Avatar asked Mar 04 '12 07:03

Exploit


2 Answers

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');
like image 175
rdlowrey Avatar answered Nov 16 '22 07:11

rdlowrey


If you get

Notice: Undefined variable: HTTP_RAW_POST_DATA

Please open your Server file add find

$server->service($HTTP_RAW_POST_DATA);

and replace with following 2 lines.

if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA);

I hope this would help.

like image 23
Milap Avatar answered Nov 16 '22 07:11

Milap