我如何解决这个奇怪的问题呢?我在我的VPS上更新了PHP到5.6.0,现在在这个特定的脚本上,当我之前没有得到它们时,我得到了这两个错误,而且他们真的不给我任何东西.
<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 />
Run Code Online (Sandbox Code Playgroud)
此脚本只是通过一些命令运行各种服务的状态,shell_exec
并以JSON的形式返回响应.它不会使用任何帖子数据,甚至不包含$_POST
在文件中.我脚本中的第一件事是:
<?php
error_reporting(0);
header('Content-Type: application/json');
Run Code Online (Sandbox Code Playgroud)
我注释掉了最后一行,并且仍然收到有关修改标题信息的警告.我不知道为什么这些错误会在旧版本(5.5.16)上正常工作时出现
一旦将文本输出到浏览器,就不能使用header().通过在错误消息中说:
在php.ini中将'always_populate_raw_post_data'设置为'-1'并使用php://输入流代替
你应该摆脱那些错误输出.
$HTTP_RAW_POST_DATA
不推荐使用(这会导致标题出现问题)
试试这个:
<?php
$postdata = file_get_contents("php://input");
?>
Run Code Online (Sandbox Code Playgroud)
阅读http://php.net/manual/en/reserved.variables.httprawpostdata.php