2017 © Pedro Peláez
 

library iab-bot-detect

Validate user agent against IAB spiders & bot list

image

elegisandi/iab-bot-detect

Validate user agent against IAB spiders & bot list

  • Monday, November 20, 2017
  • by elegisandi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 185 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 108 % Grown

The README.md

iab-bot-detect

Spider/Bot detection using IAB list, (*1)

Installation

composer require elegisandi/iab-bot-detect

Laravel/Lumen Integration

  • Add IAB's service provider to your config/app.php providers, (*2)

    elegisandi\IABBotDetect\IabServiceProvider::class, (*3)

  • Add IAB's facade to your config/app.php aliases, (*4)

    'IAB' => elegisandi\IABBotDetect\IabFacade::class, (*5)

  • Set IAB credentials in your .env file, (*6)

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

If you want to modify the package config, just run:, (*7)

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

For Lumen:, (*8)

  • Register IAB's service provider to your bootstrap/app.php, (*9)

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

Configuration

  • Generate whitelist and blacklist cache, (*11)

    php artisan iab:refresh-list, (*12)

    You may add the option --overwrite to reset cache., (*13)

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, (*14)

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

'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:, (*16)

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

S3 Auto Backup, (*17)

To enable this feature, you must set the following .env variables, (*18)

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, (*19)

  • setCredentials($credentials)

    where $credentials = a key-pair values array of your IAB user and password, (*20)

  • isValidBrowser($user_agent)

    where $user_agent could be null, (*21)

    throws an error exception, (*22)

    Returns boolean, (*23)

  • isBot($user_agent)

    where $user_agent could be null, (*24)

    throws an error exception, (*25)

    Returns boolean, (*26)

  • initialize($overwrite)

    where $overwrite = a boolean flag to overwrite cache files (_default value_: false), (*27)

    throws an error exception, (*28)

    Prepares cache files needed for bot detection process., (*29)

Error Exceptions

  • ###### IABRequestException
  • ###### IABBackupException
  • ###### InvalidIABCacheException
  • ###### InvalidIABCredentialsException

Contributing

Open an issue first to discuss potential changes/additions., (*30)

License

MIT, (*31)

The Versions

20/11 2017

dev-master

9999999-dev https://github.com/elegisandi/iab-bot-detect

Validate user agent against IAB spiders & bot list

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Elegi Sandi

bot detect elegisandi iab bot detect iab-bot-detect