speedtest/getIP.php

23 lines
833 B
PHP
Raw Normal View History

<?php
$ip="";
2017-12-20 06:28:21 +00:00
header('Content-Type: text/plain; charset=utf-8');
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip=$_SERVER['HTTP_CLIENT_IP'];
2017-12-20 06:28:21 +00:00
} elseif (!empty($_SERVER['X-Real-IP'])) {
$ip=$_SERVER['X-Real-IP'];
2017-12-20 06:28:21 +00:00
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
2017-12-20 06:28:21 +00:00
} else {
$ip=$_SERVER['REMOTE_ADDR'];
2017-12-20 06:28:21 +00:00
}
$ip=preg_replace("/^::ffff:/", "", $ip);
$isp="";
if(isset($_GET["isp"])){
$json = file_get_contents("https://ipinfo.io/".$ip."/json");
$details = json_decode($json,true);
if(array_key_exists("org",$details)) $isp.=$details["org"]; else $isp.="Unknown ISP";
if(array_key_exists("country",$details)) $isp.=" (".$details["country"].")";
echo $ip." - ".$isp;
} else echo $ip;
?>