-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcounter.php
More file actions
44 lines (38 loc) · 1.21 KB
/
counter.php
File metadata and controls
44 lines (38 loc) · 1.21 KB
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
<?php
// Allow all origins (or replace * with specific domain)
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
// Use absolute path for counter file inside /var/www
$counterFile = '/var/www/counter_data.json';
// Initialize if file doesn't exist
if (!file_exists($counterFile)) {
$initialData = [
"views" => 0,
"hits" => 0,
"created_at" => gmdate("D, d M Y 00:00:00", strtotime("2019-01-01")) . " -0000",
"last_updated" => gmdate("D, d M Y H:i:s") . " -0000"
];
file_put_contents($counterFile, json_encode($initialData));
}
// Load and update counter
$data = json_decode(file_get_contents($counterFile), true);
$data['views'] += 1;
$data['hits'] += 1;
$data['last_updated'] = gmdate("D, d M Y H:i:s") . " -0000";
// Save updated data
file_put_contents($counterFile, json_encode($data));
// Build response
$response = [
"result" => "success",
"info" => [
"sitename" => "venith",
"views" => $data['views'],
"hits" => $data['hits'],
"created_at" => $data['created_at'],
"last_updated" => $data['last_updated'],
"domain" => "veltron.net",
"tags" => ["kirby", "2000s", "music", "personal", "90s"]
]
];
echo json_encode($response, JSON_PRETTY_PRINT);
?>