PHP captures spider Crawler's code share

Source: Internet
Author: User
This article describes the PHP implementation of crawling Spider Crawler traces of a piece of code, there is a need for friends reference.

Using PHP code to analyze the Spider crawler traces in the Web log, the code is as follows:

      ' 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;} By bbs.it-home.org//What kind of spider crawler to save spider traces. According to whether the http_user_agent is empty to collect/catch spider crawler--by Bbs.it-home.org$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);}? >
  • 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.