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; }
I hope this article will be helpful to everyone’s PHP programming design.