Home  >  Article  >  Backend Development  >  PHP code to determine where the search engine is coming from and then jump to it

PHP code to determine where the search engine is coming from and then jump to it

WBOY
WBOYOriginal
2016-07-25 08:56:122389browse
  1. /**
  2. * Determine the origin of the search engine and jump to the webpage
  3. * edit: bbs.it-home.org
  4. */
  5. $flag = false;
  6. $tmp = $_SERVER['HTTP_USER_AGENT'];
  7. if(strpos($tmp, 'Googlebot') !== false){
  8. $flag = true;
  9. } else if(strpos($tmp, 'Baiduspider') >0){
  10. $flag = true;
  11. } else if(strpos($tmp, 'Yahoo! Slurp') !== false){
  12. $flag = true;
  13. } else if(strpos($tmp, 'msnbot') !== false){
  14. $flag = true;
  15. } else if(strpos($tmp, 'Sosospider') !== false){
  16. $flag = true;
  17. } else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
  18. $flag = true;
  19. } else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
  20. $flag = true;
  21. } else if(strpos($tmp, 'fast-webcrawler') !== false){
  22. $flag = true;
  23. } else if(strpos($tmp, 'Gaisbot') !== false){
  24. $flag = true;
  25. } else if(strpos($tmp, 'ia_archiver') !== false){
  26. $flag = true;
  27. } else if(strpos($tmp, 'altavista') !== false){
  28. $flag = true;
  29. } else if(strpos($tmp, 'lycos_spider') !== false){
  30. $flag = true;
  31. } else if(strpos($tmp, 'Inktomi slurp') !== false){
  32. $flag = true;
  33. }
  34. if($flag == false){
  35. //header("Location: http://www.xxx.com" . $_SERVER['REQUEST_URI']);
  36. require_once("cd.htm");
  37. // 自动转到http://www.xxx.com 对应的网页
  38. // $_SERVER['REQUEST_URI'] 为域名后面的路径
  39. // 或 header("Location: http://www.xxx.com/abc/a.php");
  40. exit();
  41. }
  42. else
  43. {
  44. require_once("index.htm");
  45. }
  46. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn