Php code sharing for crawling spider traces

Source: Internet
Author: User
Php code sharing for crawling spider traces
This article describes how to use php to capture Spider traces. For more information, see.

Use php code to analyze spider crawlers in web logs. the code is as follows:

     'Googlebot ', 'baidu' => 'baidider Ider', '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//the species of spider crawlers are kept alive. // Prevent collection based on whether HTTP_USER_AGENT is empty during Collection // capture Spider crawlers -- 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.