Heim  >  Artikel  >  php教程  >  通过IP地址查询详细信息

通过IP地址查询详细信息

WBOY
WBOYOriginal
2016-08-04 08:53:341751Durchsuche
跳至 [1] [2] [3] [全屏预览]
地址:http://www.bunian.cn/gongjv/ip/?ip=IP地址

2. [代码]返回参数     跳至 [1] [2] [3] [全屏预览]

{
    "ip": "218.12.41.188", //IP地址
    "address": "中国河北省石家庄市",//详细地址
    "state": "中国",//所属国家,国外IP默认英文
    "province": "河北省",//省
    "city": "石家庄市",//市
    "district": "",//区
    "longitude": 114.52208184,//经度
    "latitude": 38.04895831,//纬度
    "status": 0 //错误返回1
}

3. [代码]源码例子     跳至 [1] [2] [3] [全屏预览]

$ip = @$_GET['ip'];
		$url ="http://www.bunian.cn/gongjv/ip/?ip={$ip}";
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
		$data = curl_exec($ch);
		curl_close($ch);
		$ipinfo = json_decode($data,true);
		
		$ipinfo['ip']//IP地址
		$ipinfo['address'] //详细信息
		$ipinfo['state']//国家
		$ipinfo['province']//城市
		$ipinfo['city']//地区
		$ipinfo['longitude']//经度
		$ipinfo['latitude']//纬度
 
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn