Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a fut

“Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set ‘always_populate_raw_post_data’ to ‘-1’ in php.ini and use the php://input stream instead. in Unknown on line 0”

在一次写代码的过程中,因为PHP版本不同,5.6情况下。遇见了一个这样的错误后面找了很多种解决办法,下面我将用两种办法 解决这个问题。

解决办法

1、修改配置文件php.ini


always_populate_raw_post_data = -1

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a fut_第1张图片

重启php服务就OK了

2、修改代码

把  $postStr = $GLOBALS['HTTP_RAW_POST_DATA']
换成
 $postStr = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
 原理,在php5.6后面的版本 是用php://input来获取原生post参数
 (详情参见官网 http://php.net/manual/zh/reserved.variables.httprawpostdata.php)
 

你可能感兴趣的:(Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a fut)