Php function code used to determine whether a visitor is a search engine spider

Source: Internet
Author: User
Php checks whether a visitor is a search engine spider's function code. For more information, see.
/*** Determine whether it is a search engine spider ** @ author Eddy * @ return bool */function isCrawler () {$ agent = strtolower ($ _ SERVER ['http _ USER_AGENT ']); if (! Empty ($ agent) {$ spiderSite = array ("TencentTraveler", "Baiduspider +", "BaiduGame", "Googlebot", "msnbot", "sososospider + ", "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", "M J12bot "," Netcraft "," MSIECrawler "," WGet tools "," larbin "," Fish search ",); foreach ($ spiderSite as $ val) {$ str = strtolower ($ val); if (strpos ($ agent, $ str )! = False) {return true ;}}else {return false ;}}

I can find the ghost plug on the Internet, but it is not comprehensive enough to copy all the copies. here I have compiled a comprehensive code:

function is_spider(){ $robot = 0; $USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']); if(strpos($USER_AGENT,"bot")) $robot = 1; if(strpos($USER_AGENT,"spider")) $robot = 1; if(strpos($USER_AGENT,"slurp")) $robot = 1; if(strpos($USER_AGENT,"mediapartners-google")) $robot = 1; if(strpos($USER_AGENT,"fast-webcrawler")) $robot = 1; if(strpos($USER_AGENT,"altavista")) $robot = 1; if(strpos($USER_AGENT,"ia_archiver")) $robot = 1; if($robot == 1){ //do something } return ''; }

For more articles about the function code used by php to determine whether a visitor is a search engine spider, refer to the PHP Chinese website!

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.