php判断是否spider/Bot

这里返回 1 ,0 是因为要在tp3的模板里去做显示判断的。单纯php里用,直接true,false得了!

function is_bot(){
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    $botchar = "/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla|bing|sogou)/i";
    if(preg_match($botchar, $ua)) {
        return "1";
    }else{
        return "0";
    }
}

深入一下,
//备案 不是蜘蛛跳转 显示备案中
u a = s t r t o l o w e r ( ua = strtolower( ua=strtolower(_SERVER[‘HTTP_USER_AGENT’]);
b o t c h a r = " / ( b a i d u ∣ g o o g l e ∣ s p i d e r ∣ s o s o ∣ y a h o o ∣ s o h u − s e a r c h ∣ y o d a o ∣ r o b o z i l l a ∣ b i n g ∣ s o g o u ) / i " ; i f ( ! p r e g m a t c h ( botchar = "/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla|bing|sogou)/i"; if(!preg_match( botchar="/(baidugooglespidersosoyahoosohusearchyodaorobozillabingsogou)/i";if(!pregmatch(botchar, $ua)) {
header(‘Content-Type: text/html; charset=utf-8’); //编码格式
echo “备案中 备案中”;
exit;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值