PHP如何禁止掉某地区的IP访问网站且过滤搜索引擎的蜘蛛
PHP如何禁止掉某地区的IP访问网站且过滤搜索引擎的蜘蛛。 function get_ip_data(){ <br>
$ip=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip()); <br>
$ip = json_decode($ip); <br>
if($ip->code){ <br>
return false; <br>
} <br>
$data = (array) $ip->data; <br>
if($data['region']=='湖北省' && !isCrawler()){ <br>
exit('http://www.lvtao.net'); <br>
} <br>
} <br>
<br>
function isCrawler() { <br>
$spiderSite= array( <br>
"TencentTraveler", <br>
"Baiduspider+", <br>
"BaiduGame", <br>
"Googlebot", <br>
"msnbot", <br>
"Sosospider+", <br>
"Sogou web spider", <br>
"ia_archiver", <br>
"Yahoo! Slurp", <br>
"YoudaoBot", <br>
"Yahoo Slurp", <br>
"MSNBot", <br>
"Java (Often spam bot)", <br>
"BaiDuSpider", <br>
"Voila", <br>
"Yandex bot", <br>
"BSpider", <br>
"twiceler", <br>
"Sogou Spider", <br>
"Speedy Spider", <br>
"Google AdSense", <br>
"Heritrix", <br>
"Python-urllib", <br>
"Alexa (IA Archiver)", <br>
"Ask", <br>
"Exabot", <br>
"Custo", <br>
"OutfoxBot/YodaoBot", <br>
"yacy", <br>
"SurveyBot", <br>
"legs", <br>
"lwp-trivial", <br>
"Nutch", <br>
"StackRambler", <br>
"The web archive (IA Archiver)", <br>
"Perl tool", <br>
"MJ12bot", <br>
"Netcraft", <br>
"MSIECrawler", <br>
"WGet tools", <br>
"larbin", <br>
"Fish search", <br>
); <br>
if(in_array(strtolower($_SERVER['HTTP_USER_AGENT']),$spiderSite)){ <br>
return true; <br>
}else{ <br>
return false; <br>
} <br>
} <br>
<br>
//取客户端 ip <br>
function get_client_ip() <br>
{ <br>
if (isset($_SERVER)){ <br>
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){ <br>
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"]; <br>
} else if (isset($_SERVER["HTTP_CLIENT_IP"])) { <br>
$realip = $_SERVER["HTTP_CLIENT_IP"]; <br>
} else { <br>
$realip = $_SERVER["REMOTE_ADDR"]; <br>
} <br>
} else { <br>
if (getenv("HTTP_X_FORWARDED_FOR")){ <br>
$realip = getenv("HTTP_X_FORWARDED_FOR"); <br>
} else if (getenv("HTTP_CLIENT_IP")) { <br>
$realip = getenv("HTTP_CLIENT_IP"); <br>
} else { <br>
$realip = getenv("REMOTE_ADDR"); <br>
} <br>
} <br>
return $realip; <br>
}
原文地址:http://www.jb100.net/html/content-22-918-1.html
AD:真正免费,域名+虚机+企业邮箱=0元