-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient-intel.php
More file actions
65 lines (58 loc) · 2.14 KB
/
Copy pathclient-intel.php
File metadata and controls
65 lines (58 loc) · 2.14 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
header('Content-Type: application/json; charset=UTF-8');
header('Cache-Control: no-store, private, max-age=0');
header('Pragma: no-cache');
header('X-Robots-Tag: noindex, nofollow');
header('X-Content-Type-Options: nosniff');
function oll4_server_header(string $name): string {
$key = 'HTTP_' . strtoupper(str_replace('-', '_', $name));
return trim((string)($_SERVER[$key] ?? ''));
}
function oll4_country_name(string $code): string {
static $countries = [
'GR' => 'Greece',
'TH' => 'Thailand',
'GB' => 'United Kingdom',
'US' => 'United States',
'CY' => 'Cyprus',
'DE' => 'Germany',
'FR' => 'France',
'IT' => 'Italy',
'NL' => 'Netherlands',
'BG' => 'Bulgaria',
'RO' => 'Romania',
'AL' => 'Albania',
'TR' => 'Turkey',
'AE' => 'United Arab Emirates',
'IN' => 'India',
'SG' => 'Singapore',
'JP' => 'Japan',
'AU' => 'Australia',
'CA' => 'Canada',
];
$code = strtoupper($code);
return $countries[$code] ?? ($code !== '' ? $code : 'unknown');
}
$ip = oll4_server_header('CF-Connecting-IP');
if ($ip === '') {
$parts = array_map('trim', explode(',', oll4_server_header('X-Forwarded-For')));
$ip = $parts[0] ?? '';
}
if ($ip === '') {
$ip = (string)($_SERVER['REMOTE_ADDR'] ?? '');
}
$country = strtoupper(oll4_server_header('CF-IPCountry'));
$region = oll4_server_header('CF-Region');
if ($region === '') $region = oll4_server_header('CF-Region-Code');
if ($region === '') $region = oll4_server_header('CF-IPCity');
$ipVersion = 'unknown';
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) $ipVersion = 'IPv6';
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) $ipVersion = 'IPv4';
echo json_encode([
'country' => $country !== '' && $country !== 'XX' ? $country : '',
'country_name' => $country !== '' && $country !== 'XX' ? oll4_country_name($country) : '',
'region' => $region,
'ip_version' => $ipVersion,
'tls' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'),
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);