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"
     }
    }
  • 相关阅读:
    c博客06-2019-结构体&文件
    C博客作业05--2019-指针
    C语言博客作业04--数组
    Java购物车
    c博客06-2019-结构体&文件
    数组和指针的选择排序和冒泡排序区别
    C博客作业05--2019-指针
    面向对象设计大作业-图书馆系统
    java-购物车大作业
    互评-OO之接口-DAO模式代码阅读及应用
  • 原文地址:https://www.cnblogs.com/yuuje/p/14517942.html
Copyright © 2011-2022 走看看