forked from librespeed/speedtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getIP.php
21 lines (21 loc) · 788 Bytes
/
getIP.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
$ip="";
header('Content-Type: text/plain; charset=utf-8');
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['X-Real-IP'])) {
$ip=$_SERVER['X-Real-IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip=$_SERVER['REMOTE_ADDR'];
}
$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;
?>