欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淘寶ip地址查詢(xún)類(lèi)分享(利用淘寶ip庫(kù))

 更新時(shí)間:2014年01月07日 16:24:48   作者:  
需要顯示評(píng)論者的地域?qū)傩?這個(gè)特點(diǎn)可以通過(guò)記錄會(huì)員IP的地理信息來(lái)實(shí)現(xiàn),下面提供一個(gè)淘寶IP地址查詢(xún)類(lèi),簡(jiǎn)化相關(guān)的信息查詢(xún),大家參考使用吧

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

以下這個(gè)taobaoIPQuery類(lèi)將極大的簡(jiǎn)化相關(guān)的信息查詢(xún)。

復(fù)制代碼 代碼如下:

<?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)用很簡(jiǎn)單

復(fù)制代碼 代碼如下:

$ip = $_SERVER["REMOTE_ADDR"];
$ipquery = new taobaoIPQuery($ip);
$region = $ipquery->get_region();
$country = $ipquery->get_country();
$city = $ipquery->get_city();

相關(guān)文章

最新評(píng)論