PHP code for Spiders crawling Records of static pages

Source: Internet
Author: User
  1. $useragent = Addslashes (Strtolower ($_server[' http_user_agent '));

  2. if (Strpos ($useragent, ' Googlebot ')!== false) {$bot = ' Google ';}
  3. ElseIf (Strpos ($useragent, ' Mediapartners-google ')!== false) {$bot = ' Google Adsense ';}
  4. ElseIf (Strpos ($useragent, ' Baiduspider ')!== false) {$bot = ' Baidu ';}
  5. ElseIf (Strpos ($useragent, ' Sogou spider ')!== false) {$bot = ' Sogou ';}
  6. ElseIf (Strpos ($useragent, ' Sogou web ')!== false) {$bot = ' Sogou web ';}
  7. ElseIf (Strpos ($useragent, ' Sosospider ')!== false) {$bot = ' SOSO ';}
  8. ElseIf (Strpos ($useragent, ' Yahoo ')!== false) {$bot = ' Yahoo ';}
  9. ElseIf (Strpos ($useragent, ' MSN ')!== false) {$bot = ' MSN ';}
  10. ElseIf (Strpos ($useragent, ' MSNBot ')!== false) {$bot = ' msnbot ';}
  11. ElseIf (Strpos ($useragent, ' Sohu ')!== false) {$bot = ' Sohu ';}
  12. ElseIf (Strpos ($useragent, ' Yodaobot ')!== false) {$bot = ' Yodao ';}
  13. ElseIf (Strpos ($useragent, ' Twiceler ')!== false) {$bot = ' twiceler ';}
  14. ElseIf (Strpos ($useragent, ' Ia_archiver ')!== false) {$bot = ' alexa_ ';}
  15. ElseIf (Strpos ($useragent, ' Iaarchiver ')!== false) {$bot = ' Alexa ';}
  16. ElseIf (Strpos ($useragent, ' slurp ')!== false) {$bot = ' Yahoo ';}
  17. ElseIf (Strpos ($useragent, ' bot ')!== false) {$bot = ' other spiders ';}
  18. if (Isset ($bot)) {
  19. $fp = @fopen (' Bot.txt ', ' a ');
  20. Fwrite ($fp, date (' y-m-d h:i:s '). " \ t ". $_server[" REMOTE_ADDR "]." \ t ". $bot." \ t "." http://'. $_server[' server_name '].$_server["Http_x_rewrite_url"]. " \ r \ n ");
  21. Fclose ($FP);
  22. }
  23. $file = ".". $_server[http_x_rewrite_url];
  24. $f _head=substr ($file,-5);
  25. if ($f _head== ". html")
  26. {
  27. if (file_exists ($file))
  28. {
  29. Echo file_get_contents ($file);
  30. }else
  31. {
  32. Header (' http/1.1 404 Not Found ');
  33. Header ("status:404 not Found");

  34. echo "This page cannot be found";

  35. }
  36. }
  37. Else
  38. {
  39. Header (' http/1.1 404 Not Found ');
  40. Header ("status:404 not Found");
  41. echo "This page cannot be found";
  42. }
  43. ?>

Copy Code

Pseudo-Static file content:

    1. [Isapi_rewrite]

    2. # 3600 = 1 hour

    3. Cacheclockrate 3600
    4. Repeatlimit 32
    5. # Protect Httpd.ini and Httpd.parse.errors files
    6. # from accessing through HTTP
    7. rewriterule/index.html/index.php
    8. Rewriterule ^/article/(. *)/bot.php [L]
    9. Rewriterule ^/list/(. *)/bot.php [L]

Copy Code
  • 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.