Code: Select all
<?PHP
header('Access-Control-Allow-Origin: *');
$src = $_POST["src"];
$jsonString = file_get_contents('jsonFile.json');
$data = json_decode($jsonString, true);
foreach ($data as $key => $entry) {
if ($entry['src'] == $src) {
$data[$key]['counter']++;
}
}
$newJsonString = json_encode($data);
file_put_contents('jsonFile.json', $newJsonString);
?>
My json file looks like this:
Code: Select all
[
{
"src": "",
"counter": "0"
},
{
"src": "",
"counter": "0"
} // and so on...
The error in logs is PHP Warning: Invalid argument supplied for foreach() in /file.php on line 9 .
When I do
Code: Select all
var_dump($data)
Code: Select all
NULL
Thank you.