PHP implementation to determine whether access routing is a search engine robot method _php skills

Source: Internet
Author: User

This article is an example of the PHP implementation to determine whether access routing is a search engine robot method. Share to everyone for your reference. The specific analysis is as follows:

Many times we need to identify the site visitors, for real users and search engines for different actions to achieve, then first need to judge whether the search engine.

Php method is very simple to judge, through the filter $_server[' http_user_agent ' parameters can be identified, the following is an excerpt from the source of the relevant source code:

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 ' => ' 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 help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.