2

I'm fairly new to PHP and in the process of updating a system from PHP5 to PHP7.

$HTTP_RAW_POST_DATA is deprecated in PHP7 and I had read that file_get_contents("php://input") was it's equivocal replacement.

I have tested them against each other using PHP5 and found that they produce different data as follows:

$data = file_get_contents("php://input");
echo $data;
$data = $GLOBALS["HTTP_RAW_POST_DATA"];
echo $data;

with output:

pid=395,
,

In the first case the data contains the form content, in the second it doesn't. This variable being identified as empty was how the query was parsed for different purposes.

Have I missed something?

ben-ledi
  • 124
  • 5
  • I know for a fact that file_get_contents("php://input") returns all data that was passed to php's runtime STDIN. It works from the command line if you pipe data into PHP.exe or the linux executable. HTTP_RAW_POST_DATA describes itself as pertaining to the *data* passed on via *HTTP POST* requests. It seems to me that that is not exactly the same thing. – Jacob Bruinsma Nov 03 '17 at 12:08
  • For my uses, I'm going to use `$_SERVER['CONTENT_TYPE']` to filter the requests, but everything I've read suggests that these two methods are equivocal and as you say, it seems they're not. – ben-ledi Nov 03 '17 at 12:39
  • maybe http://php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data – Artem Ilchenko Nov 04 '17 at 13:28
  • and try print in other order – Artem Ilchenko Nov 04 '17 at 13:30
  • @ArtemIlchenko Why did you remove your answer? It seems to be the reight answer. – RandomSeed Nov 06 '17 at 12:54
  • @RandomSeed but that didn't answer the question – Artem Ilchenko Nov 06 '17 at 13:02
  • Are you referring to Lathrisk's comment " I assume it would have produced a deprecation error". This is normal, the variable was removed, accessing a non-existent variable only produces a notice. – RandomSeed Nov 06 '17 at 13:18

0 Answers0