2.把shielded.php上传到网站根目录/**
*
* test.php(屏蔽地方IP)
*
* @package .....
* @author ....
* @copyright Copyright (c) 2008-2013 (http://www.yidianblog.com)
* @license .....
* @version ICP 4444$
*/
header("Content-type: text/html; charset=utf-8");
$verification='XX省';//需要屏蔽省份的IP
$ip=$_SERVER['REMOTE_ADDR'];//获取访客IP
$antecedents=$_SERVER['HTTP_REFERER'];//访客来路地址
$result=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);//IP数据库来自淘宝。
$address=json_decode($result,true);
//判断访客是否属于XX省,是否来自百度,是否来自谷歌
if($address['data']['region']==$verification&&strpos($antecedents,'baidu')===false&&strpos($antecedents,'google')===false)($antecedents,'360'){
sleep(86400);//设置一个999999秒。看他们有没有这么好耐心。
Header("HTTP/1.1 204 No Content");
exit;
}
require_once(ABSPATH.'shielded.php');
<?php
function get_client_ip() {
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"),"unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR");
else if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR'];
else $ip = "unknown";
return ($ip);
}
header("Content-type: text/html; charset=utf-8");
$verification = '山东省';//修改省份
$ip = get_client_ip(); //获取当前用户的ip
$antecedents = $_SERVER['HTTP_REFERER'];//访客来路地址
$result = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);//IP数据库来自淘宝。
$address = json_decode($result,true);
if($address['data']['region'] == $verification && strpos($antecedents, 'baidu') === false && strpos($antecedents, 'google') === false){
sleep(9);
ob_start();
header('HTTP/1.503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
echo '网站备案中....';
exit;
}
?>
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛