PHP禁止個(gè)別IP訪問網(wǎng)站
想不讓某個(gè)IP訪問網(wǎng)站,可以封他的IP,下面就提供這個(gè)方法??聪旅娴拇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實(shí)現(xiàn)的限制IP投票程序IP來源分析
- php限制ip地址范圍的方法
- 用php來限制每個(gè)ip每天瀏覽頁面數(shù)量的實(shí)現(xiàn)思路
- php中限制ip段訪問、禁止ip提交表單的代碼分享
- PHP中限制IP段訪問、禁止IP提交表單的代碼
- php IP及IP段進(jìn)行訪問限制的代碼
- 如何限制訪問者的ip(PHPBB的代碼)
- 簡(jiǎn)單實(shí)現(xiàn)限定phpmyadmin訪問ip的方法
- 禁止IP訪問網(wǎng)站的多種方法分享(linux,php,nginx,apache)
- PHP 只允許指定IP訪問(允許*號(hào)通配符過濾IP)
- PHP實(shí)現(xiàn)限制IP訪問的方法
相關(guān)文章
詳解php幾行代碼實(shí)現(xiàn)CSV格式文件輸出
本篇文章主要介紹了詳解php幾行代碼實(shí)現(xiàn)CSV格式文件輸出,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07ThinkPHP在新浪SAE平臺(tái)的部署實(shí)例
這篇文章主要介紹了ThinkPHP在新浪SAE平臺(tái)的部署的實(shí)現(xiàn)方法,以實(shí)例的形式詳細(xì)講述了WBlog的完整部署過程,需要的朋友可以參考下2014-10-10ThinkPHP模板替換與系統(tǒng)常量及應(yīng)用實(shí)例教程
這篇文章主要介紹了ThinkPHP模板替換與系統(tǒng)常量及應(yīng)用,是很重要的概念,需要的朋友可以參考下2014-08-08yii2實(shí)現(xiàn)Ueditor百度編輯器的示例代碼
這篇文章主要介紹了yii2實(shí)現(xiàn)Ueditor百度編輯器的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11PHP 圖片上傳實(shí)現(xiàn)代碼 帶詳細(xì)注釋
PHP 圖片上傳實(shí)現(xiàn)代碼 帶詳細(xì)注釋,喜歡的朋友可以學(xué)習(xí)下。2010-04-04