用php代码限制国内IP访问我们网站

来源:互联网 发布:数据透视表生成图表 编辑:程序博客网 时间:2024/05/21 22:53

原理:利用淘宝的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;}
0 0
原创粉丝点击