avatar

tetsai

原创声明

本文由tetsai原创,转载请注明来源

在蜘蛛的必经之路上插入如下代码(本网站是在index.php插入的,因为设置了伪静态,基本上所有的网页都会调用index.php)

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

会在当前目录插入robotslogs.txt
效果如本网站就是

发表评论

电子邮件地址不会被公开。 必填项已用*标注