> php教程 > php手册 > PHP禁止某地区的IP访问网站且过滤搜索引擎的蜘蛛

PHP禁止某地区的IP访问网站且过滤搜索引擎的蜘蛛

WBOY
풀어 주다: 2016-06-07 11:39:56
원래의
1163명이 탐색했습니다.

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元

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿