根据访问者ip确定所属地区信息
龙行 PHP 2019-6-24
1664 0评论
//几个测试ip
//175.43.113.64 中国ip
// 172.217.161.142 谷歌ip
// 202.159.118.50 印度尼西亚ip
//$ip = $_SERVER['REMOTE_ADDR']; //本地如果测试将会得到 ::1 内网ip 相当于127.0.0.1
$ip = '172.217.161.142';
$content = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip); //连接淘宝ip库
$banned = json_decode(trim($content), true);
$lan = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
if($banned['data']['country_id'] == 'CN')
{
header("HTTP/1.0 404 Not Found");
echo 'HTTP/1.0 404 Not Found';
exit;
}else{
echo '国家是'.$banned['data']['country'];
}