1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
<?php function getIPLoc_sina($queryIP){ $ch = curl_init($url); curl_setopt($ch,CURLOPT_ENCODING , ‘utf8‘ ); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ) ; // 获取数据返回 $location = curl_exec($ch); $location = json_decode($location); curl_close($ch); $loc = "" ; if ($location===FALSE) return
"" ; if (empty($location->desc)) { $loc = $location->province.$location->city.$location->district.$location->isp; } else { $loc = $location->desc; } return
$loc; } echo getIPLoc_sina( "183.37.209.57" ); |
php利用新浪接口查询ip获取地理位置示例,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/flying-tx/p/3740097.html