Example code _php using PHP to crawl spider crawler traces

Source: Internet
Author: User

Objective

believe that many webmaster, bloggers may be most concerned about is nothing more than the inclusion of their own site, under normal circumstances, we can view the space server log files to see what the search engine has crawled our pages, however, if the use of PHP code Analysis Web log Spider crawler traces, is better and more intuitive and easy to operate! Here is the sample code, the friends who need to have a look together below.

Sample code

<?php//Capture spider reptile name or anti-capture function Isspider () {$bots = array (' Google ' => ' Googlebot ', ' Baidu '    => ' baiduspider ', ' yahoo ' => ' yahoo slurp ', ' Soso ' => ' sosospider ', ' Msn ' => ' msnbot ', ' AltaVista ' => ' scooter ', ' Sogou ' => ' Sogou spider ', ' Yodao '
  > ' Yodaobot ');
  $userAgent = Strtolower ($_server[' http_user_agent '));
      foreach ($bots as $k => $v) {if (Strstr ($v, $userAgent)) {return $k;
    Break
return false;
//Get what Spider Crawler to store after the spider traces.
According to the collection time http_user_agent is empty to prevent collecting//grasping spider crawler $spi = Isspider ();
  if ($SPI) {$TLC _thispage = addslashes ($_server[' http_user_agent '));
  $file = ' robot.txt ';
  $time = Date (' y-m-d h:i:s ', mktime ());
  $handle = fopen ($file, ' A + ');
  $PR = $_server[' Request_uri '];
  Fwrite ($handle, "time:{$time} robot:{$spi} agent:{$tlc _thispage} url:{$PR} \n\r");
Fclose ($handle); }?>

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if there are questions you can message exchange.

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.