Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP alternative to file_get_contents('php://input')

Hi all

I'm grabbing and tweaking code between 2 systems and currently using the following code to get a message for which I then process further.

At present I use a rather poor bit of code to grab the sent XML which is below, this of course brings up the deprecated error (also below) that I would like to remove by properly coding.

$dataPOST = trim(file_get_contents('php://input'));

Open in new window


PHP 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

Open in new window


Question is how can I go about changing this code and still get the XML sent to the page. I tried simplexml but that never seemed to actually get anything an allow be to pull out a specific child node

Regards
Neil
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

I don't understand - that first bit of code you showed should be the correct way to get raw (non-form-encoded) POST data. It shouldn't throw a deprecation warning...
Avatar of Neil Thompson

ASKER

perhaps I'm reading it wrong.

This is the only thing in the error logs and that is the only code so I assumed it was something I had done in that line

[08-Mar-2017 17:43:51 UTC] PHP 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

Open in new window


If this "auto population" is deprecated apart from adding the -1 is there anything else I should be adding / changing moving forwards? I don't want to upgrade in a year or 2 times and for some code to stop working for something I could fix (future proofing a bit) now.

Thanks, Neil
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Superb, thanks for clearing that up :)