PHP判断搜索引擎蜘蛛并自动记忆到文件的代码
2012-02-04 00:00
645 查看
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 网页播放器用来播放在线视频的代码(自动判断并选择视频文件类型)
- php 网页播放器用来播放在线视频的代码(自动判断并选择视频文件类型)
- PHP判断文件是否存在、是否可读、目录是否存在的代码
- 利用PHP代码实现网页自动判断转向
- PHP取二进制文件头快速判断文件类型的实现代码
- 利用PHP代码实现网页自动判断转向
- php 判断访客是否为搜索引擎蜘蛛的函数代码
- vim下php文件中自动缩排html代码
- phper 的两个实用批处理助你自动格式化php代码、清除svn、netbeans等工程文件
- php判断是否是移动端自动跳转到wap页面代码
- PHP判断来访是搜索引擎蜘蛛还是普通用户的代码小结
- php下利用curl判断远程文件是否存在的实现代码
- PHPExcel自动按照数据的列数导出文件(带demo代码)
- php中判断文件空目录是否有读写权限的函数代码
- PHP文件打开、关闭、写入的判断与执行代码
- PHP判断来访是搜索引擎蜘蛛还是普通用户的代码小结
- PHP代码统计文件大小(自动确定单位)