当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP判断搜索引擎蜘蛛并自动记忆到文件的代码

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

2019年04月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网