Php determines whether a visitor is a search engine crawler

Source: Internet
Author: User
Php determines whether a visitor is a search engine crawler

We can use HTTP_USER_AGENT to determine whether it is a spider. search engine spider has its own unique logo. The following column takes a part of it.

  1. Function is_crawler (){
  2. $ UserAgent = strtolower ($ _ SERVER ['http _ USER_AGENT ']);
  3. $ Spiders = array (
  4. 'Googlebot ', // Google crawler
  5. 'Baidider Ider ', // Baidu crawler
  6. 'Yahoo! Slurp ', // Yahoo crawler
  7. 'Yodaobot ', // Youdao crawler
  8. 'Msnbot '// Bing crawler
  9. // More crawler keywords
  10. );
  11. Foreach ($ spiders as $ spider ){
  12. $ Spider = strtolower ($ spider );
  13. If (strpos ($ userAgent, $ spider )! = False ){
  14. Return true;
  15. }
  16. }
  17. Return false;
  18. }


The following php code comes with more Spider identifiers

  1. Function isCrawler (){
  2. Echo $ agent = strtolower ($ _ SERVER ['http _ USER_AGENT ']);
  3. If (! Empty ($ agent )){
  4. $ SpiderSite = array (
  5. "TencentTraveler ",
  6. "Baiduspider + ",
  7. "BaiduGame ",
  8. "Googlebot ",
  9. "Msnbot ",
  10. "Sosospider + ",
  11. "Sogou web spider ",
  12. "Ia_archiver ",
  13. "Yahoo! Slurp ",
  14. "YoudaoBot ",
  15. "Yahoo Slurp ",
  16. "MSNBot ",
  17. "Java (Often spam bot )",
  18. "Baidusp ",
  19. "Voila ",
  20. "Yandex bot ",
  21. "BSpider ",
  22. "Twiceler ",
  23. "Sogou Spider ",
  24. "Speedy Spider ",
  25. "Google AdSense ",
  26. "Heritrix ",
  27. "Python-urllib ",
  28. "Alexa (IA Archiver )",
  29. "Ask ",
  30. "Exabot ",
  31. "Custo ",
  32. "OutfoxBot/YodaoBot ",
  33. "Yacy ",
  34. "SurveyBot ",
  35. "Legs ",
  36. "Lwp-trivial ",
  37. "Nutch ",
  38. "StackRambler ",
  39. "The web archive (IA Archiver )",
  40. "Perl tool ",
  41. "MJ12bot ",
  42. "Netcraft ",
  43. "MSIECrawler ",
  44. "WGet tools ",
  45. "Larbin ",
  46. "Fish search ",
  47. );
  48. Foreach ($ spiderSite as $ val ){
  49. $ Str = strtolower ($ val );
  50. If (strpos ($ agent, $ str )! = False ){
  51. Return true;
  52. }
  53. }
  54. } Else {
  55. Return false;
  56. }
  57. }
  58. If (isCrawler ()){
  59. Echo "Hello Spider! ";
  60. }
  61. Else {
  62. Echo "you are not a spider! ";
  63. }


Php

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.