-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheaders.php
More file actions
48 lines (36 loc) · 1.15 KB
/
Copy pathheaders.php
File metadata and controls
48 lines (36 loc) · 1.15 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
<?php /** @noinspection SpellCheckingInspection */
if (!function_exists('getallheaders')) {
die("Error: getallheaders function does not exist!");
}
function send_json($response)
{
header('Content-Type: application/json');
echo json_encode($response, JSON_PRETTY_PRINT);
}
function detect_proxy($headers)
{
$proxy_headers = array('client-ip', 'x-client-ip', 'forwarded', 'forwarded-for', 'x-forwarded-for', 'forwarded-for-ip', 'via', 'x-real-ip');
$res = [
'real_ip' => null,
'proxy_detected' => false
];
foreach ($headers as $name => $value) {
$normalized = strtolower($name);
if (in_array($normalized, $proxy_headers)) {
$res['proxy_detected'] = true;
if (preg_match('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/', $value, $matches) === 1) {
$res['real_ip'] = $matches[1];
}
}
}
return $res;
}
$headers = getallheaders();
$proxy = detect_proxy($headers);
$data = array(
'headers' => $headers,
'ip' => $_SERVER['REMOTE_ADDR'],
'real_ip' => $proxy['real_ip'],
'proxy_detected' => $proxy['proxy_detected']
);
send_json($data);