源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

淘宝ip地址查询类分享(利用淘宝ip库)

  • 时间:2020-01-31 19:14 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:淘宝ip地址查询类分享(利用淘宝ip库)
淘宝公司提供了一个很好用的IP地理信息查询接口。在这里:http://ip.taobao.com/ 以下这个taobaoIPQuery类将极大的简化相关的信息查询。
[u]复制代码[/u] 代码如下:
<?php class taobaoIPQuery {     private $m_ip;     private $m_content;     public function __construct($ip) {         if (isset($ip)) {             $this->m_ip = $ip;         } else {             $this->m_ip = "";         }         if (!empty($this->m_ip)) {             $url_handle = curl_init();             curl_setopt($url_handle, CURLOPT_URL, "http://ip.taobao.com/service/getIpInfo.php?ip=" . $this->m_ip);             curl_setopt($url_handle, CURLOPT_RETURNTRANSFER, true);             $this->m_content = curl_exec($url_handle);             curl_close($url_handle);             if ($this->m_content) {                 $this->m_content = json_decode($this->m_content);                 if ($this->m_content->{'code'} == 1) {                     exit("query error!");                 }             } else {                 exit("curl error!");             }         } else {             exit("ip address must be not empty!");         }     }     public function get_region() {         return $this->m_content->{'data'}->{'region'};     }     public function get_isp() {         return $this->m_content->{'data'}->{'isp'};     }     public function get_country() {         return $this->m_content->{'data'}->{'country'};     }     public function get_city() {         return $this->m_content->{'data'}->{'city'};     } }
调用很简单
[u]复制代码[/u] 代码如下:
$ip = $_SERVER["REMOTE_ADDR"]; $ipquery = new taobaoIPQuery($ip); $region = $ipquery->get_region(); $country = $ipquery->get_country(); $city = $ipquery->get_city();
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部