class taobaoIPQuery {

private $m_ip; priva " /> 免费影视亚洲,国产午夜精品一区二区三区视频,日韩三区免费

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

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

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

以下這個taobaoIPQuery類將極大的簡化相關的信息查詢。

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

}

調用很簡單

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

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

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

主站蜘蛛池模板: 全椒县| 红原县| 建水县| 宣汉县| 呼伦贝尔市| 凌云县| 伊吾县| 桂东县| 广河县| 高台县| 中超| 通榆县| 阿瓦提县| 合阳县| 驻马店市| 临沂市| 务川| 乳山市| 佳木斯市| 比如县| 永康市| 探索| 湖南省| 墨竹工卡县| 彩票| 彭阳县| 惠东县| 德钦县| 镇坪县| 永和县| 沙河市| 泽州县| 富蕴县| 望奎县| 方正县| 长兴县| 遵义县| 饶河县| 邵阳县| 桃园县| 平塘县|