| 
       
	WordPress当中本身有相关插件使用,其实很简单,无需任何插件,加入以下代码就可搞定。在WordPress主题文件目录下找到function文件,用代码编辑软件打开,在<?php ?>内的任意位置增加下面一段代码即可完成WordPress蜘蛛爬行日志记录生成的功能!注意代码加入位置,以免出现报错 
	
		  
	
		- 
			function get_naps_bot(){  
 
		- 
			$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);  
 
		- 
			if (strpos($useragent, 'googlebot') !== false){  
 
		- 
			return 'Googlebot';  
 
		- 
			}  
 
		- 
			if (strpos($useragent, 'msnbot') !== false){  
 
		- 
			return 'MSNbot';  
 
		- 
			}  
 
		- 
			if (strpos($useragent, 'slurp') !== false){  
 
		- 
			return 'Yahoobot';  
 
		- 
			}  
 
		- 
			if (strpos($useragent, 'baiduspider') !== false){  
 
		- 
			return 'Baiduspider';  
 
		- 
			}  
 
		- 
			if (strpos($useragent, 'sohu-search') !== false){  
 
		- 
			return 'Sohubot';  
 
		- 
			}  
 
		- 
			if (strpos($useragent, 'lycos') !== false){  
 
		- 
			return 'Lycos';  
 
		- 
			}  
 
		- 
			if (strpos($useragent, 'robozilla') !== false){  
 
		- 
			return 'Robozilla';  
 
		- 
			}  
 
		- 
			return false;  
 
		- 
			}  
 
		- 
			function nowtime(){  
 
		- 
			date_default_timezone_set('Asia/Shanghai');  
 
		- 
			$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="robotslogs.txt";  
 
		- 
			$time=nowtime();  
 
		- 
			$data=fopen($file,"a");  
 
		- 
			$PR="$_SERVER[REQUEST_URI]";  
 
		- 
			fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n page:$PR\r\n");  
 
		- 
			fclose($data);  
 
		- 
			}  
 
	 
 
	使用上面这段代码后,最好在WordPress网站的根目录创建个robotslogs.txt的文件,并且linux主机设置权限为777,然后过段时间,访问http://网址/robotslogs.txt 即可看到蜘蛛爬行记录了! 
      
      (责任编辑:最模板) |