PHP-检测国家 [英] PHP - Detect country

查看:110
本文介绍了PHP-检测国家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
用于检测用户在php中使用contry的软件包?
基于IP地址的地理位置-PHP

Possible Duplicate:
package for detecting users contry in php?
Geo Location based on IP Address - PHP

我想检测我的访客的国家.

I want to detect my visitor's country.

我在Google上找到了解决方案, 但是结果什么都没有.

And I have found the solution at Google, but the result is nothing.

你能帮我吗?

推荐答案

    <?php 
// Author: www.easyjquery.com 
$ip = $_SERVER['REMOTE_ADDR']; 
// remember chmod 0777 for folder 'cache' 
$file = "./cache/".$ip; 
if(!file_exists($file)) { 
    // request 
    $json = file_get_contents("http://api.easyjquery.com/ips/?ip=".$ip."&full=true"); 
    $f = fopen($file,"w+"); 
    fwrite($f,$json); 
    fclose($f); 
} else { 
    $json = file_get_contents($file); 
} 

$json = json_decode($json,true); 
echo "<pre>"; 
print_r($json); 

?>

演示链接

这篇关于PHP-检测国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆