找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1514|回复: 0
打印 上一主题 下一主题

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

[复制链接]

3444

主题

3465

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11142
跳转到指定楼层
楼主
发表于 2018-2-14 08:31:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            [U]复制代码[/U] 代码如下:
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="

访问查看

[url=]删除日志[/url]
";
// 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="

访问查看

[url=]删除日志[/url]
";
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";
}
            
            
您可能感兴趣的文章:
  • 用php实现让页面只能被百度gogole蜘蛛访问的方法
  • 发款php蜘蛛统计插件只要有mysql就可用
  • 发款php蜘蛛统计插件只要有mysql就可用
  • php 判断访客是否为搜索引擎蜘蛛的函数代码
  • PHP写的获取各搜索蜘蛛爬行记录代码
  • PHP屏蔽蜘蛛访问代码及常用搜索引擎的HTTP_USER_AGENT
  • 使用PHP实现蜘蛛访问日志统计
  • PHP判断来访是搜索引擎蜘蛛还是普通用户的代码小结
  • 根据user-agent判断蜘蛛代码黑帽跳转代码(js版与php版本)
  • 利用php抓取蜘蛛爬虫痕迹的示例代码
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端