php通过淘宝API查询IP地址归属等信息

来源:互联网 发布:sql2000还原数据库 编辑:程序博客网 时间:2024/05/15 20:00

这篇文章主要介绍了php通过淘宝API查询IP地址归属等信息的相关资料,需要的朋友可以参考下

/*  *根据腾讯IP分享计划的地址获取IP所在地,比较精确  */function getIPLoc_QQ($queryIP){   $url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.$queryIP;   $ch = curl_init($url);   curl_setopt($ch,CURLOPT_ENCODING ,'gb2312');   curl_setopt($ch, CURLOPT_TIMEOUT, 10);   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回   $result = curl_exec($ch);   $result = mb_convert_encoding($result, "utf-8", "gb2312"); // 编码转换,否则乱码   curl_close($ch);   preg_match("@<span>(.*)</span></p>@iU",$result,$ipArray);   $loc = $ipArray[1];   return $loc; }

http://www.jb51.net/article/76960.htm

/** * 通过淘宝IP接口获取IP地理位置 * @param string $ip * @return: string **/function getCity($ip){    $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;    $ch = curl_init();    $timeout = 5;    curl_setopt ($ch, CURLOPT_URL, $url);    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);    $file_contents = curl_exec($ch);    curl_close($ch);    $ipinfo=json_decode($file_contents);    if($ipinfo->code=='1'){        return false;    }    $city = $ipinfo->data->region.$ipinfo->data->city;    return $city;}
/*  *根据新浪IP查询接口获取IP所在地  */function getIPLoc_sina($queryIP){   $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.$queryIP;   $ch = curl_init($url);   //curl_setopt($ch,CURLOPT_ENCODING ,'utf8');   curl_setopt($ch, CURLOPT_TIMEOUT, 10);   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回   $location = curl_exec($ch);   $location = json_decode($location);   curl_close($ch);   $loc = "";   if($location===FALSE) return "";   if (emptyempty($location->desc)) {     $loc = $location->province.$location->city.$location->district.$location->isp;   }else{     $loc = $location->desc;   }   return $loc; } 
function getCity($ip){    $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;    $ip=json_decode(file_get_contents($url));    if((string)$ip->code=='1'){        return false;    }    $city = $ip->data->region.$ip->data->city.' ' .$ip->data->isp;    return $city;}
echo getCity("221.226.5.1");  function getCity($ip){      //淘宝查询接口      $url = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;      //用curl发送接收数据      $ch = curl_init($url);      curl_setopt($ch, CURLOPT_ENCODING, 'utf8');      curl_setopt($ch, CURLOPT_TIMEOUT, 10);      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);      $location = curl_exec($ch);      $location = json_decode($location);      curl_close($ch);      return($location->data->city);  }  //stdClass Object ( [code] => 0 [data] => stdClass Object ( [country] => 中国 [country_id] => CN [area] => 华东 [area_id] => 300000 [region] => 江苏省 [region_id] => 320000 [city] => 南京市 [city_id] => 320100 [county] => [county_id] => -1 [isp] => 电信 [isp_id] => 100017 [ip] => 221.226.5.1 ) )   
阅读全文
0 0