Skip to content

Instantly share code, notes, and snippets.

@blueandhack
Created August 10, 2013 07:27
Show Gist options
  • Save blueandhack/6199456 to your computer and use it in GitHub Desktop.
Save blueandhack/6199456 to your computer and use it in GitHub Desktop.
屏蔽某个地区IP
<?php
header("Content-type: text/html; charset=utf-8");
$verification = '安徽省';//需要屏蔽省份的IP
$ip = $_SERVER['REMOTE_ADDR'];//获取访客IP
$antecedents = $_SERVER['HTTP_REFERER'];//访客来路地址
$result = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);
$address = json_decode($result,true);
//判断访客是否属于广东省,是否来自百度,是否来自谷歌
if($address['data']['region'] == $verification && strpos($antecedents, 'baidu') === false && strpos($antecedents, 'google') === false){
sleep(1800);//设置一个999999秒。看他们有没有这么好耐心。
Header("HTTP/1.1 204 No Content");
exit;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment