简体   繁体   中英

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

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');

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM