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

<div class="codetitle"><a style="CURSOR: pointer" data="51467" class="copybut" id="copybut51467" onclick="doCopy('code51467')"> 代码如下:

<div class="codebody" id="code51467">
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="
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
访问查看

<a href=\"../?action=delbot\">删除日志
";
// 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="
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
访问查看

<a href=\"../?action=delbot\">删除日志
";
fputs($botfile,$fileHeader);
fclose($botfile);
}else {
$botfile=fopen("./log/bot.html","a+");
} //$size="当前文件大小为:".$filesize."
";转载注明www.chhua.com $useragent="USER:".$useragent."
";
$date="TIME:".$date."
";
$ip="IP:".$ip."
";
$url="URL:".$url."

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...