-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathget.php
57 lines (45 loc) · 1.21 KB
/
get.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
55
56
57
<?php
$params = $_POST;
if (empty($params)) {
$params = $_GET;
}
define('DATA_FILE', "blacklist.json");
function readJson($myFile) {
$theData = "{}";
if (file_exists($myFile)) {
$fh = fopen($myFile, 'r') or err(404, "internal (read) error!");
$i = 0;
$run = 1;
$retr = 3;
while ($run) {
if (flock($fh, LOCK_SH)) { // do an exclusive lock
$theData = fread($fh, filesize($myFile));
flock($fh, LOCK_UN); // release the lock
break;
} else {
if ($i++ < $retr) {
usleep(100 * 1000);
} else {
err(404, "internal (read) error!");
}
}
}
fclose($fh);
}
return $theData;
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
if ($params["version"]) {
if (file_exists(DATA_FILE)) {
$ft = filemtime(DATA_FILE);
} else {
$ft = 0;
}
print('{ "version" : "' . $ft . '" }');
} else {
echo readJson(DATA_FILE);
}
?>