mirror of https://github.com/dnomd343/echoIP
Dnomd343
4 years ago
3 changed files with 8 additions and 41 deletions
@ -1,17 +0,0 @@ |
|||
<?php |
|||
|
|||
function getClientIp() { |
|||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|||
$ip = $_SERVER['HTTP_CLIENT_IP']; |
|||
} elseif (!empty($_SERVER['HTTP_X_REAL_IP'])) { |
|||
$ip = $_SERVER['HTTP_X_REAL_IP']; |
|||
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|||
$ip = preg_replace('/,.*/', '', $ip); |
|||
} else { |
|||
$ip = $_SERVER['REMOTE_ADDR']; |
|||
} |
|||
return preg_replace('/^::ffff:/', '', $ip); |
|||
} |
|||
|
|||
?> |
@ -1,30 +1,14 @@ |
|||
<?php |
|||
|
|||
include("getInfo.php"); |
|||
include("getIP.php"); |
|||
|
|||
function sendHeaders() { |
|||
header('Content-Type: application/json; charset=utf-8'); |
|||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, s-maxage=0'); |
|||
header('Cache-Control: post-check=0, pre-check=0', false); |
|||
header('Pragma: no-cache'); |
|||
} |
|||
|
|||
$ip = $_GET['ip']; |
|||
if ($ip) { |
|||
if (!filter_var($ip, \FILTER_VALIDATE_IP)) { |
|||
echo "Illegal IP format".PHP_EOL; |
|||
exit; |
|||
} |
|||
} else { |
|||
$ip = getClientIp(); |
|||
} |
|||
|
|||
if ($_GET['cli'] == "true") { |
|||
echo getIPInfo($ip, true); |
|||
} else { |
|||
sendHeaders(); |
|||
echo getIPInfo($ip, false); |
|||
if (!filter_var($ip, \FILTER_VALIDATE_IP)) { |
|||
echo "Illegal IP format".PHP_EOL; |
|||
exit; |
|||
} |
|||
|
|||
echo getIPInfo($ip); |
|||
|
|||
?> |
|||
|
Loading…
Reference in new issue