PHP 限制国内IP访问 代码实例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/forest_fire/article/details/50944721

PHP 限制国内IP访问 代码实例

2013 年 9 月 5 日 – 00:52 | 1,688 views | Favorite收藏
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)

主要是利用淘宝的IP接口来判断IP 是否是国内的ip 是国内的就不允许访问

$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;
}




http://ip.taobao.com/service/getIpInfo.php?ip=112.124.103.61


{"code":0,"data":{"country":"\u4e2d\u56fd","country_id":"CN","area":"\u534e\u4e1c","area_id":"300000","region":"\u6d59\u6c5f\u7701","region_id":"330000","city":"\u676d\u5dde\u5e02","city_id":"330100","county":"","county_id":"-1","isp":"\u963f\u91cc\u4e91","isp_id":"1000323","ip":"112.124.103.61"}}


展开阅读全文

没有更多推荐了,返回首页