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!