若要实现此功能,操作如下
1、根目录建立一个robots.php文件,将如下代码加入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| function get_naps_bot() { $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); if (strpos($useragent, 'googlebot') !== false){ return 'Google'; }
if (strpos($useragent, 'baiduspider') !== false){ return '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){ 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.phpfensi.com.txt"; $time=nowtime(); $data=fopen($file,"a"); fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispagen"); fclose($data); }
|
将其上传于你的主题目录内.
2.在Footer.php或header.php的适当位置添加以下代码调用robots.php,查看源代码打印帮助:
程序原理:通过对蜘蛛标识符(如Baiduspider、Googlebot)的判断,记录蜘蛛爬行时间,并生成日志文件robotslogs.txt于根目录.