I am writing some simple PHP to receive a POST from another system with a JSON payload. That request is Content-Type: application/json.
I'm simply attempting to dump the json into a txt file as a starting point, but that isn't happening. Here's the PHP file, any suggestions/corrections would be much appreciated!
<?php
ini_set("display_errors", "On");
session_start();
$raw_json = file_get_contents('php://input');
$cooked_json = json_decode($raw_json);
$myfile = fopen('/home/wgordon/log.txt','a');
$fp = fwrite($myfile, $cooked_json);
fclose($myfile);
?>
From the look of it, the initial value of $raw_json would be a string. When you try to access it as an array, you're only going to get a smaller string back. When you pass that to json_decode, it's probably going to return null.
You need to inspect that first value of $raw_json. If it is coming in as a query string of name/value pairs, you'll need to decode it (using split() or something similar) before you can treat it like an array