-
Notifications
You must be signed in to change notification settings - Fork 1
/
comm.php
54 lines (42 loc) · 1.31 KB
/
comm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
date_default_timezone_set("Asia/Colombo");
$dateAndTimeC = date('Y-m-d h:i:sa');
$ipAddressC = $_SERVER['REMOTE_ADDR'];
$browserC = $_SERVER['HTTP_USER_AGENT'];
$sendObj = new \stdClass();
if (isset($_POST)) {
$str_data = file_get_contents("comments.json");
$data = json_decode($str_data,true);
// die($data);
// foreach ($data as $key => $value) {
// echo($value['name']);
// }
$myFile = "logs.json";
$arr_data = array(); // create empty array
try{
//Get form data
$formdata = array(
'date' =>$dateAndTimeC,
'IP' => $ipAddressC,
'browser' => $browserC
);
//Get data from existing json file
$jsondata = file_get_contents($myFile);
// converts json data into array
$arr_data = json_decode($jsondata, true);
// print_r($formdata);
// Push user data to array
// array_push($arr_data,$formdata);
$arr_data[] = $formdata;
//Convert updated array to JSON
$jsondata = json_encode($arr_data, JSON_PRETTY_PRINT);
//write json data into data.json file
if(file_put_contents($myFile, $jsondata)) {
}
// echo "error";
}catch (Exception $e) {
// echo 'Caught exception: ', $e->getMessage(), "\n";
}
die(json_encode($data));
}
?>