温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

淘宝ip地址查询类方法教程

发布时间:2021-10-08 14:34:01 来源:亿速云 阅读:157 作者:iii 栏目:开发技术

这篇文章主要介绍“淘宝ip地址查询类方法教程”,在日常操作中,相信很多人在淘宝ip地址查询类方法教程问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”淘宝ip地址查询类方法教程”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

复制代码 代码如下:

<?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();

到此,关于“淘宝ip地址查询类方法教程”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI