zoukankan      html  css  js  c++  java
  • 通过淘宝IP库获取定位

    http://ip.aliyun.com/outGetIpInfo?accessKey=alibaba-inc&ip=113.108.182.52

    //获取ip地址
    function get_ip(){
        if (isset($_SERVER)) {
            if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                $realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
                $realip = $_SERVER['HTTP_CLIENT_IP'];
            } else {
                $realip = $_SERVER['REMOTE_ADDR'];
            }
        } else {
            if (getenv("HTTP_X_FORWARDED_FOR")) {
                $realip = getenv( "HTTP_X_FORWARDED_FOR");
            } elseif (getenv("HTTP_CLIENT_IP")) {
                $realip = getenv("HTTP_CLIENT_IP");
            } else {
                $realip = getenv("REMOTE_ADDR");
            }
        }
        return $realip;
    }
     
       //淘宝库ip接口
        public function get_ip()
        {
            $ip = get_ip();
            $url = file_get_contents("http://ip.aliyun.com/outGetIpInfo?accessKey=alibaba-inc&ip=$ip");
            $res1 = json_decode($url,true);
            $data =$res1;
            if ($data) {
                $this->response(array("status" => 1, "msg" => "查询成功", "result" => $data), 'json');
            } else {
                $this->response(array("status" => -1, "msg" => "查询失败"), 'json');
            }
        }

    获取打印的数据

    {
    code: 0
    data: {
     area: ""
     area_id: ""
     city: "广州"
     city_id: "440100"
     country: "中国"
     country_id: "CN"
     county: ""
     county_id: null
     ip: "113.108.182.52"
     isp: "电信"
     isp_id: "100017"
     queryIp: "113.108.182.52"
     region: "广东"
     region_id: "440000"
     msg: "query success"
     }
    }
  • 相关阅读:
    ibatis的优缺点及可行性分析
    NHibernate优点和缺点:
    IbatisNet的介绍和使用
    bat(续七)-for语句(循环结构)
    bat(续五)-获取批处理文件所在路径
    Shell函数参数
    Shell函数:Shell函数返回值、删除函数、在终端调用函数
    Shell break和continue命令
    Shell until循环
    Shell while循环
  • 原文地址:https://www.cnblogs.com/yuuje/p/14517942.html
Copyright © 2011-2022 走看看