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); };