欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP判断搜索引擎蜘蛛并自动记忆到文件的代码

程序员文章站 2024-02-04 22:03:58
复制代码 代码如下: function write_naps_bot(){ $useragent=get_naps_bot(); // echoexit($useragen...
复制代码 代码如下:

function write_naps_bot(){
$useragent=get_naps_bot();
// echoexit($useragent);
if ($useragent=="false") return false ;
date_default_timezone_set("asia/shanghai");
$date=date("y-m-d h:i:s");
$ip=$_server[remote_addr];
$url="http://".$_server[http_host].$_server[request_uri];
// echoexit($url);转载注明www.chhua.com
if (!file_exists("./log/bot.html")){
$botfile=fopen("./log/bot.html", "w");
$fileheader="<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
<title>访问查看</title>
</head>
<a href=\"../?action=delbot\">删除日志</a><hr>
";
// echoexit($botfile);转载注明www.chhua.com

fputs($botfile, $fileheader);
fclose($botfile);
}else
{ $filesize=filesize("./log/bot.html");
if ($filesize>=100000){
$botfile=fopen("./log/bot.html", "w");
$fileheader="<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
<title>访问查看</title>
</head>
<a href=\"../?action=delbot\">删除日志</a><hr>
";
fputs($botfile, $fileheader);
fclose($botfile);
}else {
$botfile=fopen("./log/bot.html", "a+");
}

//$size="<b>当前文件大小为:</b>".$filesize."<br>";转载注明www.chhua.com

$useragent="<b>user:</b>".$useragent."<br>";
$date="<b>time:</b>".$date."<br>";
$ip="<b>ip:</b>".$ip."<br>";
$url="<b>url:</b><a href='$url' target='_blank'>".$url."</a><br><br>";
$filestr=$useragent.$date.$ip.$url;
fputs($botfile, $filestr);
fclose($botfile);
}
}

function get_naps_bot() {
$useragent = strtolower($_server['http_user_agent']);
if(strpos($useragent, 'googlebot') !== false){
return '<font color=blue>googlebot</font>';
}
if(strpos($useragent, 'msnbot') !== false){
return 'msnbot';
}
if(strpos($useragent, 'slurp') !== false){
return '<font color=green>yahoobot</font>';
}
if(strpos($useragent, 'baiduspider') !== false){
return '<font color=red>baiduspider</font>';
}
if(strpos($useragent, 'sohu-search') !== false){
return 'sohubot';
}
if(strpos($useragent, 'lycos') !== false){
return 'lycos';
}

if(strpos($useragent, 'robozilla') !== false){
return 'robozilla';
}
return "false";
}

上一篇: php摘要生成函数(无乱码)

下一篇: