Bug #69699 [Opn->Nab]: file_get_contents("php://input") throws warnings

From: Date: Sun, 24 May 2015 22:02:38 +0000
Subject: Bug #69699 [Opn->Nab]: file_get_contents("php://input") throws warnings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192866@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69699&edit=1

 ID:                 69699
 Updated by:         cmb@php.net
 Reported by:        lewismoten at gmail dot com
 Summary:            file_get_contents("php://input") throws warnings
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Output Control
 Operating System:   Linux
 PHP Version:        5.6.9
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Well, your code is fine, and it will still work with PHP 7.0.0.
The deprecation notice is shown, because the $HTTP__RAW_POST_DATA
and with it the ini setting always_populate_raw_post_data will be
removed from PHP 7.0.0, so everybody using this setting with
either 0 or 1 knows about the issue.

If you don't have access to php.ini to set
always_populate_raw_post_data to -1, you should contact your
server admins (maybe the hosting company).

An alternative is to remove E_DEPRECATED warnings from
error_reporting, what is customary on production systems anyway.
Doing so can be done from PHP as well (see error_reporting()).


Previous Comments:
------------------------------------------------------------------------
[2015-05-24 14:41:48] lewismoten at gmail dot com

Description:
------------
I have a PHP page where a JSON object is being passed in the raw post data. To get this object, I
use file_get_contents("php://input"). I'm getting a warning that in the future, PHP
will not support raw streams of input. To get around this issue with the current version, it says I
need to update the php.ini file setting for always_populate_raw_post_data. The problem is that the
suggested work around is not possible since I do not have access to modify the php.ini file.

Even if I was able to fix this in the php.ini file, I am concerned about the removal of posting raw
data to PHP pages in the future.

I would like to turn this warning off in pages that have this problem via ini_set

I also need to be able to continue to post via RAW data to my PHP pages in the future.

Test script:
---------------
// use the post method with raw data (less than 2048 bytes)
// and send to a PHP page with the following code

if($_SERVER['REQUEST_METHOD'] !== 'POST') exit;
if((int) $_SERVER['CONTENT_LENGTH'] > 2048) exit;
$input = file_get_contents("php://input");
$data = json_decode($input);

Expected result:
----------------
No warning message.

Able to receive raw post data.

Actual result:
--------------
Warning is displayed:

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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69699&edit=1


Thread (4 messages)

« previous php.bugs (#192866) next »