PHP判断搜索引擎蜘蛛并自动记忆到文件的代码
作者:bea
代码如下: 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="h
代码如下:
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中如何判断AJAX提交的数据
- 用PHP书写安全的脚本代码
- PHP中register_globals参数为OFF和ON的区别(register_globals 使用详解)
- PHP中使用数组实现堆栈数据结构的代码
- PHP使用数组实现队列
- mysql数据库差异比较的PHP代码
- PHP反转字符串函数strrev()函数的用法
- PHP __autoload函数(自动载入类文件)的使用方法
- PHP函数spl_autoload_register()用法和__autoload()介绍
- PHP中的cookie不用刷新就生效的方法
- PHP对象转换为数组函数(递归方法)
- PHP投票系统防刷票判断流程分析
- php摘要生成函数(无乱码)
- 写出高质量的PHP程序
- 组合算法的PHP解答方法
- php处理斐波那契数列非递归方法
- PHP逐行输出(ob_flush与flush的组合)
- 非常好用的两个PHP函数 serialize()和unserialize()