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訪問的方法
相關(guān)文章
php中計算未知長度的字符串哪個字符出現(xiàn)的次數(shù)最多的代碼
php中計算未知長度的字符串哪個字符出現(xiàn)的次數(shù)最多的代碼,需要的朋友可以參考下2012-08-08
詳解laravel passport OAuth2.0的4種模式
這篇文章主要介紹了laravel passport OAuth2.0的4種模式,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11
thinkphp5.1框架實現(xiàn)格式化mysql時間戳為日期的方式小結(jié)
這篇文章主要介紹了thinkphp5.1框架實現(xiàn)格式化mysql時間戳為日期的方式,結(jié)合實例形式分析了thinkPHP針對mysql時間戳格式轉(zhuǎn)換的相關(guān)操作技巧,需要的朋友可以參考下2019-10-10
php檢查函數(shù)必傳參數(shù)是否存在的實例詳解
這篇文章主要介紹了php檢查函數(shù)必傳參數(shù)是否存在的實例詳解的相關(guān)資料,需要的朋友可以參考下2017-08-08
PHP中使用file_get_contents post數(shù)據(jù)代碼例子
這篇文章主要介紹了PHP中使用file_get_contents post數(shù)據(jù)代碼例子,本文直接給出代碼實例,需要的朋友可以參考下2015-02-02

