想获得登录用户的国家分布情况。
现在登录用户表里只有记录用户的IP
感觉用IP地址转化为国家花费太长时间了(每一个都得在一个网址上转国家?)
大家有没有好的方法?
可以根据IP知道用户的国家?

解决方案 »

  1.   

    这个比较简单,你使用api接口就可以了。比如新浪api。查询后你在自己取出值显示OK<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
    <script type="text/javascript">
    //format参数设置返回格式 js/json
    //ip 要查询IP 可选
    //反回格式如下:
    //var remote_ip_info = {"ret":1,"start":"117.89.35.0","end":"117.89.35.255","country":"\u4e2d\u56fd","province":"\u6c5f\u82cf","city":"\u5357\u4eac","district":"\u767d\u4e0b","isp":"\u7535\u4fe1","type":"","desc":""};
    console.log(remote_ip_info["country"]+’,'+remote_ip_info["province"]+"省"+’,'+remote_ip_info["city"]+"市")//中国,江苏省,南京市
    </script>
      

  2.   

        
      
    function get_ip_place(){       
      
    $ip=file_get_contents("http://fw.qq.com/ipaddress");       
      
    $ip=str_replace('"',' ',$ip);       
      
    $ip2=explode("(",$ip);       
      
    $a=substr($ip2[1],0,-2);       
      
    $b=explode(",",$a);       
      
    return $b;       
      
    }       
      
    $ip=get_ip_place();       
      
    print_r($ip); 
        
      
      
       
      
    代码须联网使用的,使用腾迅的一个api,即http://fw.qq.com/ipaddress  
      
    然后用php进行了简单的处理,使返回的结果用数组形式显示:  
      
    即Array ( [0] =>123.5.115.119 [1] => [2] => 河南省 [3] => 新乡市)  
      
       
      
    ps:同理用JS也可以通过腾迅的API获得IP地址和IP地址所在的地区。  
      

  3.   

    谢谢楼上的。
    但是有个问题 
    我是有一堆的IP,查询的时候一次性变为国家 这样子 貌似要多次链接其他网站来转换IP,会非常非常慢