|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-05-24 14:41 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 09:00:01 2025 UTC |
Thanks for the response. I did try modifying the error reporting. The problem appears that this depreciation message seems to be written out before the page executes. This appears at the beginning of my file, but I still get the depreciation error written directly to my page, instead of being able to catch it: error_reporting(E_ERROR); set_error_handler("onError", E_ALL); function onError($number, $message, $file, $line) { header('Content-type: application/json'); $o = new stdClass; $o->success = false; $o->message = $message; echo json_encode($o); die(); }