1. 程式人生 > >php獲取客服埠IP 以及實體地址 網路

php獲取客服埠IP 以及實體地址 網路

<?php 
function getIP()
{
    static $realip;
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (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"); } else if (getenv("HTTP_CLIENT_IP")) { $realip = getenv("HTTP_CLIENT_IP"); } else { $realip
= getenv("REMOTE_ADDR"); } } return $realip; } function getCity($ip = '') { global $a_country,$a_area,$a_region,$a_city,$a_isp; $taobao = 'http://ip.taobao.com/service/getIpInfo.php?ip='; $url = $taobao.$ip; $json = file_get_contents($url); $json = json_decode($json, true); $a_country
=$json['data']['country']; $a_area=$json['data']['area']; $a_region=$json['data']['region']; $a_city=$json['data']['city']; $a_isp=$json['data']['isp']; } $kip=getIP(); getCity($kip); $doli=$a_country.$a_area.$a_region.$a_city."&nbsp;".$a_isp; echo "你的ip是:" . $kip . "<br>"; echo "你的其他資訊是:" . $doli . "<br>"; /** * 獲取 IP 地理位置 * 淘寶IP介面 * @Return: array function getCity($ip = '') { $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; $ip=json_decode(file_get_contents($url)); if((string)$ip->code=='1'){ return false; } $data = (array)$ip->data; return $data; } echo "<br>"; $ak=remote_ip_info.city; $kip=getIP(); echo "<br>"; var_dump(getCity($kip)); echo "<br>"; echo "你的ip是:" . $kip . "<br>"; echo "你的其他:" . $ak . "<br>"; */ ?>