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

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

WBOY
發布: 2016-06-07 11:39:56
原創
1170 人瀏覽過

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
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板