【问题标题】:Not inserting on DB bot/spider/crawlers activity不插入数据库机器人/蜘蛛/爬虫活动
【发布时间】:2012-08-29 09:16:19
【问题描述】:

在我的网页上,我注册了访问者的活动以供分析。

但是结果会受到机器人访问的影响。

我想知道在将数据保存到数据库之前检查 user_agent 是否是一种聪明的方法(请参阅底部的功能)。我担心我的网络上的繁重负载。有很多机器人,我不知道在每次访问中检查 user_agent 与 30 个机器人列表是否有效。

$bots = array( 'googlebot', 'msnbot', 'baidu', ... up to 30 );
$isRobot = false;
$ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );

foreach ( $bots as $bot ) {
        if ( strpos( $ua, $bot ) !== false )
            $isRobot = true;
        }

        if ( !$isRobot ) {
            // insert in the db
        }
    }

另一种方法是允许在数据库上插入并在之后删除它们。

【问题讨论】:

    标签: php mysql bots


    【解决方案1】:

    使用in_array:

    $bots = array( 'googlebot', 'msnbot', 'baidu', ... up to 30 );
    $isRobot = false;
    $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );
    
    if(in_array($ua, $bots)) {
        $isRobot = true;
    }
    if ( !$isRobot ) {
        // insert in the db
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 2010-12-03
      • 1970-01-01
      • 2013-11-30
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多