码迷,mamicode.com
首页 > Web开发 > 详细

PHP根据IP查找地区

时间:2015-09-20 16:10:44      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

function GetIpLookup($ip = ‘‘){  
    if(empty($ip)){  
        $ip = GetIp();  
    }  
    $res = @file_get_contents(http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip= . $ip);  
    if(empty($res)){ return false; }  
    $jsonMatches = array();  
    preg_match(#\{.+?\}#, $res, $jsonMatches);  
    if(!isset($jsonMatches[0])){ return false; }  
    $json = json_decode($jsonMatches[0], true);  
    if(isset($json[ret]) && $json[ret] == 1){  
        $json[ip] = $ip;  
        unset($json[ret]);  
    }else{  
        return false;  
    }  
    return $json;  
}  
  
  
$ipInfos = GetIpLookup(123.125.114.144); //baidu.com IP地址  
var_dump($ipInfos);  

 

PHP根据IP查找地区

标签:

原文地址:http://www.cnblogs.com/phpweige/p/4823414.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!