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.phpproviderselegisandi\IABBotDetect\IabServiceProvider::class -
Add IAB's facade to your
config/app.phpaliases'IAB' => elegisandi\IABBotDetect\IabFacade::class -
Set IAB credentials in your
.envfileIAB_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-listYou may add the option
--overwriteto 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_agentcould be nullthrows an error exception
Returns
boolean -
isBot($user_agent)
where
$user_agentcould be nullthrows an error exception
Returns
boolean -
initialize($overwrite)
where
$overwrite= abooleanflag to overwrite cache files (default value:false)throws an error exception
Prepares cache files needed for bot detection process.
Error Exceptions
Contributing
Open an issue first to discuss potential changes/additions.
License
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elegisandi/iab-bot-detect 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dialogflow php sdk
A Laravel 5 Package Provider to Identify/detect a user's browser, device, operating system and Language
AWS Elasticsearch Service for Laravel/Lumen
Laravel 5.6 Monolog custom telegram channel
MobileDetect library for YiiFramework 1.x
Yii2 extension for Mobile-Detect library
统计信息
- 总下载量: 13.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-11