PHP程序自動記錄搜索引擎蜘蛛來訪

網上找的程序,修改了下,使用方法新建一個robots.php的文件,將以下代碼Copy進文件內保存,使用include robots.php將文件包含在你要統計的php頁面中,好是footer或者header之類全站都要調用的php文件內即可:

?

<?php
function get_naps_bot()
{
	$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
/*if (strpos($useragent, 'googlebot') !== false){
	return 'Google';
}*/
if (strpos($useragent, 'sosospider') !== false){
	return 'SOSO';
}
/*if (strpos($useragent, '360Spider') !== false){
	return '360';
}
if (strpos($useragent, 'bingbot') !== false){
	return 'Bing';
}*/
if (strpos($useragent, 'baiduspider') !== false){
	return 'Baidu';
}
/*if (strpos($useragent, 'sohu-search') !== false){
	return 'Sohu';
}*/
return false;
}
function nowtime(){
	$date=gmdate("Y-n-j H:i:s",time()+8*3600);
	return $date;
}
$searchbot = get_naps_bot();
if ($searchbot) {
	$tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
	$url=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
	$file="robotslogs.txt";
	$time=nowtime();
	$data=fopen($file,"a");
	fwrite($data,"Time:$time robot:$searchbot URL:$url\n");
	fclose($data);
}
?>
點擊返回頂部
秒速飞艇哪里的彩票