dev-master
9999999-dev https://github.com/elegisandi/iab-bot-detectValidate user agent against IAB spiders & bot list
MIT
The Requires
- php >=7.0
by Elegi Sandi
bot detect elegisandi iab bot detect iab-bot-detect
Wallogit.com
2017 © Pedro Peláez
Validate user agent against IAB spiders & bot list
Spider/Bot detection using IAB list, (*1)
composer require elegisandi/iab-bot-detect
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)
Generate whitelist and blacklist cache, (*11)
php artisan iab:refresh-list, (*12)
You may add the option
--overwriteto reset cache., (*13)
<?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',
]
<?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
where
$user_agent= User Agent string, (*19)
where
$credentials= a key-pair values array of your IAB user and password, (*20)
where
$user_agentcould be null, (*21)throws an error exception, (*22)
Returns boolean, (*23)
where
$user_agentcould be null, (*24)throws an error exception, (*25)
Returns boolean, (*26)
where
$overwrite= abooleanflag to overwrite cache files (_default value_:false), (*27)throws an error exception, (*28)
Prepares cache files needed for bot detection process., (*29)
Open an issue first to discuss potential changes/additions., (*30)
MIT, (*31)
Validate user agent against IAB spiders & bot list
MIT
bot detect elegisandi iab bot detect iab-bot-detect