PHP/MySQL - an array filter for bots

前端 未结 4 1384
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 07:19

I\'m making a hit counter. I have a database and I store the IP and $_SERVER[\'HTTP_USER_AGENT\']; of the visitors. Now I need to add a filter, so I can put awa

4条回答
  •  清酒与你
    2020-12-17 08:06

    And why not?

    $bots=array('google', 'bing', 'yahoo', 'bot', 'crawler', 'baiduspider');
    if(!preg_match('/('.join('|', $bots).')/is', $_SERVER['HTTP_USER_AGENT'])){
      //record to db code
    }
    

提交回复
热议问题