记录各搜索蜘蛛爬行记录php代码

可以记录Baidu,Google,Bing,Yahoo,Soso,Sogou,Yodao爬行网站的记录

代码如下:

01<?php
02//http://www.tongqiong.com
03function get_naps_bot()
04{
05$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
06
07if (strpos($useragent, 'googlebot') !== false){
08return 'Google';
09}
10
11if (strpos($useragent, 'baiduspider') !== false){
12return 'Baidu';
13}
14if (strpos($useragent, 'msnbot') !== false){
15return 'Bing';
16}
17
18if (strpos($useragent, 'slurp') !== false){
19return 'Yahoo';
20}
21
22if (strpos($useragent, 'sosospider') !== false){
23return 'Soso';
24}
25
26if (strpos($useragent, 'sogou spider') !== false){
27return 'Sogou';
28}
29
30if (strpos($useragent, 'yodaobot') !== false){
31return 'Yodao';
32}
33return false;
34}
35
36function nowtime(){
37$date=date("Y-m-d.G:i:s");
38return $date;
39}
40
41$searchbot = get_naps_bot();
42
43if ($searchbot) {
44$tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
45$url=$_SERVER['HTTP_REFERER'];
46$file="www.tongqiong.com.txt";
47$time=nowtime();
48$data=fopen($file,"a");
49fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
50fclose($data);
51}
52//http://www.tongqiong.com
53?>