PHP to determine whether a visitor is a search engine crawler

Source: Internet
Author: User

We can judge whether it is a spider by http_user_agent, the spider of search engine has its own unique symbol, the following list takes part.

    1. function Is_crawler () {
    2. $userAgent = Strtolower ($_server[' http_user_agent ');
    3. $spiders = Array (
    4. ' Googlebot ',//Google crawler
    5. ' Baiduspider ',//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. }
Copy Code
The following PHP code comes with more spider logos
  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. "Baiduspider",
  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 essence!" ";
  60. }
  61. else{
  62. echo "You're not a Spider-Man!" ";
  63. }
Copy Code
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.