Improved ISP detection code
This commit is contained in:
parent
c0f99fb89b
commit
344d0cd396
|
@ -15,7 +15,7 @@ if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||||
$ip = $_SERVER['X-Real-IP'];
|
$ip = $_SERVER['X-Real-IP'];
|
||||||
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||||
$ip = preg_replace("/,.*/", "", $ip); # hosts are comma-separated, client is first
|
$ip = preg_replace("/,.*/", "", $ip); # hosts are comma-separated, client is first
|
||||||
} else {
|
} else {
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
}
|
}
|
||||||
|
@ -55,22 +55,27 @@ if (isset($_GET["isp"])) {
|
||||||
$json = file_get_contents("https://ipinfo.io/" . $ip . "/json");
|
$json = file_get_contents("https://ipinfo.io/" . $ip . "/json");
|
||||||
$details = json_decode($json, true);
|
$details = json_decode($json, true);
|
||||||
$rawIspInfo=$details;
|
$rawIspInfo=$details;
|
||||||
if (array_key_exists("org", $details))
|
if (array_key_exists("org", $details)){
|
||||||
$isp .= $details["org"];
|
$isp .= $details["org"];
|
||||||
else
|
$isp=preg_replace("/AS\d{1,}\s/","",$isp); //Remove AS##### from ISP name, if present
|
||||||
|
}else{
|
||||||
$isp .= "Unknown ISP";
|
$isp .= "Unknown ISP";
|
||||||
if (array_key_exists("country", $details))
|
}
|
||||||
$isp .= ", " . $details["country"];
|
if (array_key_exists("country", $details)){
|
||||||
|
$isp .= ", " . $details["country"];
|
||||||
|
}
|
||||||
$clientLoc = NULL;
|
$clientLoc = NULL;
|
||||||
$serverLoc = NULL;
|
$serverLoc = NULL;
|
||||||
if (array_key_exists("loc", $details))
|
if (array_key_exists("loc", $details)){
|
||||||
$clientLoc = $details["loc"];
|
$clientLoc = $details["loc"];
|
||||||
|
}
|
||||||
if (isset($_GET["distance"])) {
|
if (isset($_GET["distance"])) {
|
||||||
if ($clientLoc) {
|
if ($clientLoc) {
|
||||||
$json = file_get_contents("https://ipinfo.io/json");
|
$json = file_get_contents("https://ipinfo.io/json");
|
||||||
$details = json_decode($json, true);
|
$details = json_decode($json, true);
|
||||||
if (array_key_exists("loc", $details))
|
if (array_key_exists("loc", $details)){
|
||||||
$serverLoc = $details["loc"];
|
$serverLoc = $details["loc"];
|
||||||
|
}
|
||||||
if ($serverLoc) {
|
if ($serverLoc) {
|
||||||
try {
|
try {
|
||||||
$clientLoc = explode(",", $clientLoc);
|
$clientLoc = explode(",", $clientLoc);
|
||||||
|
|
Loading…
Reference in a new issue