You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
826 B
PHTML

7 months ago
<?php
$post_number = $_GET["post"];
// header("Content-Type: application/json; charset=UTF-8");
// $data = $json_decode($_POST["post1"],false);
// echo json_encode($data);
$filename = "data.json";
$myfile = fopen($filename, "r") or die("Unable to open file!");
// # first read the data from the file
$data = fread($myfile, filesize($filename));
$data_json = json_decode($data, true);
fclose($myfile);
$currentcount = $data_json[$post_number];
// # then add +1 to "data", which is the counter, by overwriting $data
$data_json[$post_number] = $currentcount+1;
var_dump ($data_json);
$data_json_updated = json_encode($data_json);
echo $data_json_updated;
# and save this number to the file again
$myfile = fopen($filename, "w") or die("Unable to open file!");
fwrite($myfile, $data_json_updated);
fclose($myfile);
?>