Blogger Information
Blog 4
fans 0
comment 0
visits 3323
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
获取ip地址的位置信息
薈瞢的博客
Original
680 people have browsed it

echo  getcposition(getIP());

//传一个ip地址 

function getIP(){

    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地址转化

function getcposition($ip){

 

    $res1 = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=$ip");

    $res1 = json_decode($res1,true);

 

//print_r($res1);

   if ($res1[ "code"]==0){

        return $res1['data']["country"].$res1['data'][ "region"].$res1['data']["city"]."_".$res1['data'][ "isp"];

    }else{

        return "未知";

    } 

}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post