欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php判断访问者是搜索引擎还是真实用户的代码

程序员文章站 2022-04-22 22:08:12
...
  1. /**
  2. * 判断访问来源 搜索引擎还是真实用户
  3. * site bbs.it-home.org
  4. */
  5. function is_bot()
  6. {
  7. /* This function will check whether the visitor is a search engine robot */
  8. //根据需要扩充此数组
  9. $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
  10. "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
  11. "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
  12. "crawler", "bbs.it-home.org", "Googlebot", "Scooter", "Slurp",
  13. "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
  14. "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
  15. "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
  16. "Butterfly","Twitturls","Me.dium","Twiceler");
  17. foreach($botlist as $bot)
  18. {
  19. if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
  20. return true; // Is a bot
  21. }
  22. return false; // Not a bot
  23. }
  24. ?>
复制代码