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

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

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

相关文章

dede3.1分页文字采集过滤规则详说(图文教程)续二

dede3.1分页文字采集过滤规则详说(图文教程)续二

稍微了解dede采集规则的朋友上篇内容完全可以略过,下面看看如何以静制动、以不变就万变地解决分页采集问题。二、采集新目标目标地址:1、http://www.tiansou.net/Htm...

解析dedecms空间迁移步骤详解

1.在新空间重新安装一次原版本的DEDECMS,然后把旧站的所有数据,这里的数据指的是文件,即除了根目录下文件夹include下的配置文件config_base.php外的所有文件覆盖到...

关于php中一些字符串总结

php自带的一个截取字符串的函数,只能处理英文,数字的不能截取中文混排的哦,有需要的朋友可以参考,后面的比较好用,第一个主要是给初学者学学用的。 php //构造字符串 $str...

php中ltrim()、rtrim()与trim()删除字符空格实例

本文实例讲述了php中ltrim()、rtrim()与trim()删除字符空格的方法。分享给大家供大家参考。具体分析如下: php中的trim函数不能像asp中的一样,可以自动删除所有空...

PHP正则匹配日期和时间(时间戳转换)的实例代码

先来一个比较简单实用的代码 日期YYYY-MM-DD $str = ''; $isMatched = preg_match('/^\d{4}(\-|\/|.)\d{1,2}\1\d{...