原理:利用淘宝的IP接口来判断IP,是否是国内的ip,是国内(CN)的就不允许访问。
$ip = $_SERVER['REMOTE_ADDR'];
$content = file_get_contents(‘http://ip.taobao.com/service/getIpInfo.php?ip=’.$ip);
$banned = json_decode(trim($content), true);
$lan = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
if((!empty($banned['data']['country_id']) && $banned['data']['country_id'] == ‘CN’) || strstr($lan, ‘zh’))
{
header(“HTTP/1.0 404 Not Found”);
echo ‘HTTP/1.0 404 Not Found’;
exit;
}
本文介绍了一种使用淘宝提供的IP接口来判断客户端IP地址的方法,并通过该方法实现对中国大陆IP的访问限制。当检测到访问请求来自国内时,将返回404错误,阻止访问。
4315





