elegisandi/iab-bot-detect 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

elegisandi/iab-bot-detect

Composer 安装命令:

composer require elegisandi/iab-bot-detect

包简介

Validate user agent against IAB spiders & bot list

README 文档

README

Spider/Bot detection using IAB list

Installation

composer require elegisandi/iab-bot-detect

Laravel/Lumen Integration

  • Add IAB's service provider to your config/app.php providers

    elegisandi\IABBotDetect\IabServiceProvider::class
    
  • Add IAB's facade to your config/app.php aliases

    'IAB' => elegisandi\IABBotDetect\IabFacade::class
    
  • Set IAB credentials in your .env file

      IAB_USER=your-iab-user
      IAB_PASSWORD=your-iab-password
    

If you want to modify the package config, just run:

php artisan vendor:publish --provider=elegisandi\\IABBotDetect\\IabServiceProvider

For Lumen:

  • Register IAB's service provider to your bootstrap/app.php

    $app->register(elegisandi\IABBotDetect\IabServiceProvider::class);      
    

Configuration

  • Generate whitelist and blacklist cache

    php artisan iab:refresh-list
    

    You may add the option --overwrite to reset cache.

Basic Usage

<?php

use elegisandi\IABBotDetect\Validator;

$user_agent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
$config = [
    'user' => 'YOUR_IAB_USER',
    'password' => 'YOUR_IAB_PASSWORD'
];

try {
    $bot_detect = new Validator($user_agent, $config);
        
    if($bot_detect->isValidBrowser()) {
        echo 'valid browser';
    } else {
        echo 'invalid browser';
    }
} catch (\Exception $e) {
    // fallback user agent validation
}

S3 Auto Backup

To enable this feature, you must add the following into the 2nd argument of the constructor

's3_backup' => true,
's3_bucket' => 'YOUR_IAB_S3_BUCKET,
's3_region' => 'YOUR_AWS_REGION',
'aws_credentials' => [
    'key' => 'YOUR_AWS_ACCESS_KEY_ID',
    'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
]

Laravel/Lumen Usage

<?php

use IAB;

$user_agent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';

try {
    if(IAB::isValidBrowser($user_agent)) {
        echo 'valid browser';
    } else {
        echo 'invalid browser';
    }
} catch (\Exception $e) {
    // fallback user agent validation
}

For Lumen:

try {
    if(app('iab')->isValidBrowser($user_agent)) {
        echo 'valid browser';
    } else {
        echo 'invalid browser';
    }
} catch (\Exception $e) {
    // fallback user agent validation
}

S3 Auto Backup

To enable this feature, you must set the following .env variables

IAB_S3_BACKUP=true
IAB_S3_BUCKET=your-s3-bucket-name
AWS_REGION=your-s3-region
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key

Methods

  • setUserAgent($user_agent)

    where $user_agent = User Agent string

  • setCredentials($credentials)

    where $credentials = a key-pair values array of your IAB user and password

  • isValidBrowser($user_agent)

    where $user_agent could be null

    throws an error exception

    Returns boolean

  • isBot($user_agent)

    where $user_agent could be null

    throws an error exception

    Returns boolean

  • initialize($overwrite)

    where $overwrite = a boolean flag to overwrite cache files (default value: false)

    throws an error exception

    Prepares cache files needed for bot detection process.

Error Exceptions

  • IABRequestException
  • IABBackupException
  • InvalidIABCacheException
  • InvalidIABCredentialsException

Contributing

Open an issue first to discuss potential changes/additions.

License

MIT

elegisandi/iab-bot-detect 适用场景与选型建议

elegisandi/iab-bot-detect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.39k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「detect」 「bot」 「elegisandi」 「iab」 「bot detect」 「iab-bot-detect」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 elegisandi/iab-bot-detect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 elegisandi/iab-bot-detect 我们能提供哪些服务?
定制开发 / 二次开发

基于 elegisandi/iab-bot-detect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-11