This repository has been archived on 2022-12-28. You can view files and clone it, but cannot push or open issues or pull requests.
apiOld/ipinfo/api.php
2021-02-07 22:28:02 +08:00

15 lines
456 B
PHP

<?php
header("Content-type:application/json;charset=utf-8");
if(empty($_GET['ip'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_GET['ip'];
}
$ipinfo=@file_get_contents("http://whois.pconline.com.cn/ipJson.jsp?ip=".$ip."&json=true");
$ipinfo=iconv("GB2312","UTF-8",$ipinfo);
$ipinfo=json_decode($ipinfo);
foreach($ipinfo as $ii=>$ii2){
$$ii = $ii2;
}
echo '{"ip":"'.$ip.'","pro":"'.$pro.'","city":"'.$city.'","addr":"'.trim($addr).'"}';