Home > Backend Development > PHP Tutorial > PHP implements a method to determine whether the access source is a search engine robot, the source search engine_PHP tutorial

PHP implements a method to determine whether the access source is a search engine robot, the source search engine_PHP tutorial

WBOY
Release: 2016-07-13 09:57:08
Original
890 people have browsed it

php implements the method to determine whether the access source is a search engine robot, the source search engine

This article describes the example of php to determine whether the access source is a search engine robot . Share it with everyone for your reference. The specific analysis is as follows:

Many times we need to identify the source of website visitors and perform different actions for real users and search engines. Then we first need to determine whether it is a search engine.

The PHP judgment method is very simple. You can identify it by filtering the $_SERVER['HTTP_USER_AGENT'] parameter. The following is an excerpt of the relevant source code of an open source program:

private function getRobot()
{
 if (empty($_SERVER['HTTP_USER_AGENT']))
 {
  return false;
 }
 $searchEngineBot = array(
  'googlebot'=>'google',
  'mediapartners-google'=>'google',
  'baiduspider'=>'baidu',
  'msnbot'=>'msn',
  'yodaobot'=>'yodao',
  'youdaobot'=>'yodao',
  'yahoo! slurp'=>'yahoo',
  'yahoo! slurp china'=>'yahoo',
  'iaskspider'=>'iask',
  'sogou web spider'=>'sogou',
  'sogou push spider'=>'sogou',
  'sosospider'=>'soso',
  'spider'=>'other',
  'crawler'=>'other',
 );
 $spider = strtolower($_SERVER['HTTP_USER_AGENT']);
 foreach ($searchEngineBot as $key => $value)
 { 
  if (strpos($spider, $key)!== false)
  {
   return $value;
  }
 }
 return false;
}
public function isRobot()
{
 if($this->getRobot()!==false)
 {
  return true;
 }
 return false;
}
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/984623.htmlTechArticlephp implements the method to determine whether the access source is a search engine robot. The source search engine example in this article describes the php implementation A method to determine whether the access source is a search engine robot. Share...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template