国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

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

2024-05-04 23:21:01
字體:
來源:轉載
供稿:網友

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

以下這個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();

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定边县| 惠水县| 云安县| 乡宁县| 武义县| 登封市| 延吉市| 工布江达县| 财经| 浙江省| 丹棱县| 武强县| 阿城市| 白城市| 塔河县| 平泉县| 西吉县| 西林县| 关岭| 儋州市| 迁西县| 始兴县| 哈尔滨市| 达尔| 淳安县| 洞头县| 唐河县| 乌拉特中旗| 上杭县| 桐乡市| 溧水县| 东丰县| 辽宁省| 棋牌| 叶城县| 遂溪县| 湘阴县| 噶尔县| 无极县| 北川| 镇安县|