PHP implementation search engine crawling code sharing

Source: Internet
Author: User
This article mainly and you introduced the PHP record search engine crawl record implementation code, and then in the text to you to supplement the introduction of PHP search spiders crawl record code, the need for friends can refer to, hope to help everyone.

Here's the full code:

Record search engine crawl record $searchbot = Get_naps_bot (); if ($searchbot) {$TLC _thispage = addslashes ($_server[' http_user_agent '); $url = $_server[' Http_referer ']; $file = web_p ATH. ' Robotslogs.txt '; $date = Date (' y-m-d h:i:s '); $data = fopen ($file, ' a '); Fwrite ($data, "Time: $date Robot: $searchbot URL: $TLC _thispage/r/n"); Fclose ($data);}

Web_path is the root directory path for index.php under define, meaning that the Robotslogs.txt file is placed under the root directory.

The spider crawl record is obtained through Get_naps_bot (), then the data is stored in the variable $tlc_thispage by processing it through addslashes.

Fopen opens the Robotslogs.txt file, writes the data through the function fwrite, and closes it through the function fclose.

Because I don't think it is necessary, so I deleted the code on my website, so there is no example of the effect.

Ps:php get the code for each search spider crawl record

Support the following search engines: Baidu,google,bing,yahoo,soso,sogou,yodao crawl site Records!

Code:

<?php/*** get search engine crawl record * edit by Www.jb51.net*/function Get_naps_bot () {$ useragent = Strtolower ($_server[' http_user_agent '); if (Strpos ($useragent, ' Googlebot ')!== false) {return ' Google ';} if (Strpos ($useragent, ' Baiduspider ')!== false) {Retur n ' Baidu '; } if (Strpos ($useragent, ' MSNBot ')!== false) {return ' Bing ';} if (Strpos ($useragent, ' slurp ')!== false) {return ' Yahoo ' ; } if (Strpos ($useragent, ' Sosospider ')!== false) {return ' Soso ';} if (Strpos ($useragent, ' Sogou spider ')!== false) {RET Urn ' Sogou '; } if (Strpos ($useragent, ' Yodaobot ')!== false) {return ' Yodao ';} return false; } function Nowtime () {$date =date ("y-m-d.g:i:s"); return $date;} $searchbot = Get_naps_bot (); if ($searchbot) {$TLC _thispage = addslashes ($_server[' http_user_agent '); $url =$_server[' http_referer ']; $file = " Www.jb51.net.txt "; $time =nowtime (); $data =fopen ($file, "a"); Fwrite ($data, "Time: $time Robot: $searchbot URL: $TLC _thispage\n"); Fclose ($data); }; 

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.