Php record the implementation code of Search Engine crawling record, php Search Engine

Source: Internet
Author: User

Php record the implementation code of Search Engine crawling record, php Search Engine

The complete code is as follows:

// Record search engine crawling records $ searchbot = get_naps_bot (); if ($ searchbot) {$ tlc_thispage = addslashes ($ _ SERVER ['HTTP _ USER_AGENT ']); $ url = $ _ SERVER ['HTTP _ referer']; $ file = WEB_PATH.'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_pathis the root directory of defineunder index.php. It is suggested that the robotslogs.txt file is stored in the root directory.

Passget_naps_bot()Obtain the spider crawling record, and then process it through addslashes to store the data in the variable $ tlc_thispage.

Fopenopen the robotslogs.txt file and write data through the fwrite function. You can close the file by using the fclose function.

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

PS: php code for retrieving spider crawling records

Supports the following search engines: Baidu, Google, Bing, Yahoo, Soso, Sogou, and Yodao website crawling records!

Code:

<? Php/*** retrieve search engine crawling 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, 'baidider ider ')! = False) {return 'baidu';} if (strpos ($ useragent, 'msnbot ')! = False) {return 'bin';} if (strpos ($ useragent, 'slup ')! = False) {return 'yahoo ';} if (strpos ($ useragent, 'sosospider ')! = False) {return 'sososo';} if (strpos ($ useragent, 'sogou spider ')! = False) {return '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) ;}?>

Summary

The above is the php record search engine crawling record introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in time. Thank you very much for your support for the help House website!

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.