PHP禁止個別IP訪問網(wǎng)站
想不讓某個IP訪問網(wǎng)站,可以封他的IP,下面就提供這個方法??聪旅娴拇a。
function get_ip_data(){
$ip=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip());
$ip = json_decode($ip);
if($ip->code){
return false;
}
$data = (array) $ip->data;
if($data['region']=='湖北省' && !isCrawler()){
exit('http://www.a.net');
}
}
function isCrawler() {
$spiderSite= array(
"TencentTraveler",
"Baiduspider+",
"BaiduGame",
"Googlebot",
"msnbot",
"Sosospider+",
"Sogou web spider",
"ia_archiver",
"Yahoo! Slurp",
"YoudaoBot",
"Yahoo Slurp",
"MSNBot",
"Java (Often spam bot)",
"BaiDuSpider",
"Voila",
"Yandex bot",
"BSpider",
"twiceler",
"Sogou Spider",
"Speedy Spider",
"Google AdSense",
"Heritrix",
"Python-urllib",
"Alexa (IA Archiver)",
"Ask",
"Exabot",
"Custo",
"OutfoxBot/YodaoBot",
"yacy",
"SurveyBot",
"legs",
"lwp-trivial",
"Nutch",
"StackRambler",
"The web archive (IA Archiver)",
"Perl tool",
"MJ12bot",
"Netcraft",
"MSIECrawler",
"WGet tools",
"larbin",
"Fish search",
);
if(in_array(strtolower($_SERVER['HTTP_USER_AGENT']),$spiderSite)){
return true;
}else{
return false;
}
}
//取客戶端 ip
function get_client_ip()
{
if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$realip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$realip = $_SERVER["REMOTE_ADDR"];
}
} else {
if (getenv("HTTP_X_FORWARDED_FOR")){
$realip = getenv("HTTP_X_FORWARDED_FOR");
} else if (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
return $realip;
}
- 用php代碼限制國內(nèi)IP訪問我們網(wǎng)站
- PHP實現(xiàn)的限制IP投票程序IP來源分析
- php限制ip地址范圍的方法
- 用php來限制每個ip每天瀏覽頁面數(shù)量的實現(xiàn)思路
- php中限制ip段訪問、禁止ip提交表單的代碼分享
- PHP中限制IP段訪問、禁止IP提交表單的代碼
- php IP及IP段進行訪問限制的代碼
- 如何限制訪問者的ip(PHPBB的代碼)
- 簡單實現(xiàn)限定phpmyadmin訪問ip的方法
- 禁止IP訪問網(wǎng)站的多種方法分享(linux,php,nginx,apache)
- PHP 只允許指定IP訪問(允許*號通配符過濾IP)
- PHP實現(xiàn)限制IP訪問的方法
相關文章
ThinkPHP模板替換與系統(tǒng)常量及應用實例教程
這篇文章主要介紹了ThinkPHP模板替換與系統(tǒng)常量及應用,是很重要的概念,需要的朋友可以參考下2014-08-08