WSTMAll后台错误:Automatically populating $HTTP_RAW_POST_DATA is deprecated

原创 zhaoliang  2017-11-22 12:19  阅读 562 views 次

新买了一套WSTMALL的系统进行二次开发,开发过程后台经常弹窗提示:系统发生错误undefined,抽时间排查了一下,终于定位问题,原来是PHP版本升级导致。浏览器调试过程中发现在ajax数据返回前有报错信息输出,导致header头信息被破坏掉而无法被正常处理。

<br />
<b>Deprecated</b>:  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 <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent in <b>Unknown</b> on line <b>0</b><br />

估计WSTMALL在前期的开发过程中,使用了相对比较低php版本或者降低亦或是关闭了PHP错误级别,代码里出现了多处post类还带参数类的ajax请求,而比较新的php版本,尤其是php5.6或php7,已经不再明确支持此类原生请求或直接摒弃掉。

解决方案

1.将post的ajax请求中的空参数{}内,随意添加一项无用参数,比如{t:1},强烈推荐使用此类方案

2.按错误提示将php.ini中的always_populate_raw_post_data改为-1,非常不建议此方法

; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
; to disable this feature and it will be removed in a future version.
; If post reading is disabled through enable_post_data_reading,
; $HTTP_RAW_POST_DATA is *NOT* populated.
; http://php.net/always-populate-raw-post-data
;always_populate_raw_post_data = -1

3.使用php://input替换$HTTP_RAW_POST_DATA

PHP官网原文

使用 always_populate_raw_post_data 会导致在填充 $HTTP_RAW_POST_DATA 时产生 E_DEPRECATED 错误。 请使用 php://input 替代 $HTTP_RAW_POST_DATA, 因为它可能在后续的 PHP 版本中被移除。 设置 always_populate_raw_post_data 为 -1 (这样会强制 $HTTP_RAW_POST_DATA 未定义,所以也不回导致 E_DEPRECATED 的错误) 来体验新的行为。

 

WarningThis feature was DEPRECATED in PHP 5.6.0, and REMOVED as of PHP 7.0.0.

本文地址:http://blog.58cm.cn:8088/archives/487.html
版权声明:本文为原创文章,版权归 zhaoliang 所有,欢迎分享本文,转载请保留出处!

评论已关闭!