Created
August 10, 2013 07:27
-
-
Save blueandhack/6199456 to your computer and use it in GitHub Desktop.
屏蔽某个地区IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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