class taobaoIPQuery {

private $m_ip; priva " /> 久久综合色播五月,欧美激情20,日本成人黄色片

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

淘寶ip地址查詢類分享(利用淘寶ip庫)

淘寶公司提供了一個很好用的IP地理信息查詢接口。在這里:http://ip.taobao.com/

以下這個taobaoIPQuery類將極大的簡化相關(guān)的信息查詢。

復制代碼 代碼如下:
<?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'};
    }

}

調(diào)用很簡單

復制代碼 代碼如下:
$ip = $_SERVER["REMOTE_ADDR"];
$ipquery = new taobaoIPQuery($ip);
$region = $ipquery->get_region();
$country = $ipquery->get_country();
$city = $ipquery->get_city();

php技術(shù)淘寶ip地址查詢類分享(利用淘寶ip庫),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 青岛市| 金平| 武清区| 黄石市| 重庆市| 丰宁| 荔浦县| 汉川市| 福泉市| 沅江市| 平乡县| 苏尼特左旗| 阿拉善左旗| 赤城县| 司法| 富裕县| 乐亭县| 嘉定区| 土默特右旗| 乐安县| 灌南县| 海伦市| 那曲县| 宝丰县| 道真| 新龙县| 桐城市| 城步| 赣榆县| 青州市| 图木舒克市| 奉新县| 内黄县| 新巴尔虎右旗| 高陵县| 黄梅县| 牡丹江市| 调兵山市| 平顺县| 湘乡市| 南投市|