Home  >  Article  >  Backend Development  >  The php spider crawls normally, and the user visits and transfers the specified page code

The php spider crawls normally, and the user visits and transfers the specified page code

WBOY
WBOYOriginal
2016-07-25 09:13:321253browse


Sometimes the content we display is for search engines, and many users do not need to see it, so I will share the php code below. The spider will crawl it normally, and the user will transfer the specified page code when visiting
  1. $ v = false;
  2. $tmp = $_SERVER['HTTP_USER_AGENT'];
  3. if(strpos($tmp, 'Googlebot') !== false){
  4. $v = true;
  5. } else if(strpos ($tmp, 'Baiduspider') >0){
  6. //echo 'Baidu';
  7. $v = true;
  8. } else if(strpos($tmp, 'Yahoo! Slurp') !== false ){
  9. //echo 'Yahoo';
  10. ' $v = true;
  11. } else if(strpos($tmp, 'msnbot') !== false){
  12. //echo 'Msn';
  13. $v = true;
  14. } else if(strpos($tmp, 'Sosospider') !== false){
  15. //echo 'Sosospider';
  16. $v = true;
  17. } else if(strpos ($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
  18. //echo 'Youdao';
  19. $v = true;
  20. } else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
  21. //echo 'Sogou';
  22. $v = true;
  23. } else if(strpos($tmp, 'fast-webcrawler') !== false){
  24. //echo 'Alltheweb';
  25. $v = true;
  26. } else if(strpos($ tmp, 'Gaisbot') !== false){
  27. //echo 'Gais';
  28. $v = true;
  29. } else if(strpos($tmp, 'ia_archiver') !== false){
  30. //echo 'Alexa';
  31. ' $v = true;
  32. } else if(strpos($tmp, 'altavista') !== false){
  33. //echo 'AltaVista';
  34. ' $v = true;
  35. } else if(strpos($tmp, 'lycos_spider') !== false){
  36. //echo 'Lycos';
  37. $v = true;
  38. } else if(strpos($tmp, 'Inktomi slurp') !== false){
  39. //echo 'Inktomi';
  40. $v = true;
  41. }

  42. if($v != true){
  43. header("Location: http://www.xiaobei668.com");
  44. }
  45. ?>
Copy code
Search engine, Baidu, Soso, false


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