Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors in Unknown on Line 0 after PHP Upgrade [closed]

Tags:

php

How do I go about troubleshooting this weird problem? I updated PHP on my VPS to 5.6.0 and now on this one specific script I am getting these two errors when I didn't get them before, and they really don't give me anything to go by.

<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 />

This script just runs some commands to the status of various services through shell_exec and returns the response as JSON. It doesn't doesn't use any post data, or even contain $_POST in the file. The first thing in my script is:

<?php

error_reporting(0);

header('Content-Type: application/json');

I commented out that last line, and still got the warning about modify heading information. I don't have any idea why these errors are coming up when they worked fine on the older version (which was 5.5.16)

like image 664
ecnepsnai Avatar asked Sep 22 '14 23:09

ecnepsnai


2 Answers

You cannot use header() once text has been output to the browser. By doing as it is said in the error message:

set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead

you should get rid of those error outputs.

like image 170
Adam Sinclair Avatar answered Nov 03 '22 00:11

Adam Sinclair


$HTTP_RAW_POST_DATA is deprecated (this is causing the problem with the header)

Try this:

<?php
$postdata = file_get_contents("php://input");
?> 

Read http://php.net/manual/en/reserved.variables.httprawpostdata.php

like image 41
Guilherme Nascimento Avatar answered Nov 02 '22 23:11

Guilherme Nascimento