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

yipeiwu_com6年前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";
}

相关文章

php生成短域名函数

php生成短域名函数 public function createRandCode($string) { $code = ''; $hex_code = '1qaz2...

PHP单例模式应用示例【多次连接数据库只实例化一次】

本文实例讲述了PHP单例模式应用。分享给大家供大家参考,具体如下: 以前刚开始工作的时候经常连接数据库,每次用到数据库的时候就要用new进行实例并连接一次,当时因为连接数据库的次数不是很...

php实现映射操作实例详解

php实现映射操作实例详解

本文实例讲述了php实现映射操作。分享给大家供大家参考,具体如下: 映射 映射,或者射影,在数学及相关的领域经常等同于函数。基于此,部分映射就相当于部分函数,而完全映射相当于完全函数。...

PHP获取表单所有复选框的值的方法

通常来说,php中总是只获取最后一个复选框的值,那么如何才能获取所有复选框的值? 解决办法如下: form表单的部分代码如下: <input type="checkbox" n...

PHP实现的用户注册表单验证功能简单示例

PHP实现的用户注册表单验证功能简单示例

本文实例讲述了PHP实现的用户注册表单验证功能。分享给大家供大家参考,具体如下: 注册界面 register.html <h1>用户注册</h1>...