Prohibit IP addresses in a region from accessing the website, and do not filter the spider-PHP source code of the search engine.

Source: Internet
Author: User
Prohibit IP addresses in a region from accessing the website, and do not filter the search engine's spider php code.

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'] = 'hubei province '&&! IsCrawler () {exit (' http://www.lvtao.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 ;}// obtain the client ipfunction get_client_ip () {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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.