发布于 2014-12-02 14:17:42 | 286 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

淘宝网(taobao)

淘宝网是亚太地区较大的网络零售商圈,由阿里巴巴集团在2003年5月10日投资创立。淘宝网现在业务跨越C2C(个人对个人)、B2C(商家对个人)两大部分。


本文为大家讲解的是淘宝ip地址查询类分享(利用淘宝ip 接口),感兴趣的同学参考下.

需要显示评论者的地域属性,这个特点可以通过记录会员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();


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务