jonathansudhakar/botdetector

Laravel 4 的机器人检测器

dev-master 2014-08-21 03:27 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:56:26 UTC


README

安装

添加到 composer.json

require: "jonathansudhakar/botdetector": "dev-master"

添加到 app/config/app.php 中的 'providers'

'Jonathansudhakar\Botdetector\BotdetectorServiceProvider'

基本用法

检测当前请求是否为机器人

Botdetector::isBot(); // returns true or false
Botdetector::detect()->isBot(); // returns true or false

检测当前请求是否为人

Botdetector::isHuman(); // returns true or false
Botdetector::detect()->isHuman(); // returns true or false

检测用户代理字符串是否为机器人(或人)

Botdetector::isBot("user-agent-string"); // returns true or false
Botdetector::detect("user-agent-string")->isBot(); // returns true or false

更多选项

获取用户代理字符串

Botdetector::detect()->getAgent(); //returns user-agent string
Botdetector::detect("user-agent-string")->getAgent(); //returns user-agent string

获取除了 '/bot|crawl|slurp|spider/i' 和 '/Chrome/|Firefox/|Safari//i' 之外正在测试的用户代理字符串列表。

Botdetector::detect()->getHumans(); //returns array with defaults
Botdetector::detect()->getBots(); //returns array with defaults
Botdetector::detect()->getHumans(false); //returns array without defaults
Botdetector::detect()->getBots(false); //returns array without defaults

添加除了 '/bot|crawl|slurp|spider/i' 和 '/Chrome/|Firefox/|Safari//i' 之外的用户代理字符串测试列表。

Botdetector::detect()->addHumans(array('list','of','human','user-agent strings'))->isBot(); //adds an array of humans to list of defaults
Botdetector::detect()->addBots(array('list','of','bot','user-agent strings'))->isBot(); //adds an array of bots to list of defaults

选项:不测试包括 '/bot|crawl|slurp|spider/i' 和 '/Chrome/|Firefox/|Safari//i' 的默认值。

Botdetector::detect()->ignoreDefaults()->isBot(); // Defaults to true if not set
Botdetector::detect()->ignoreDefaults(false)->isBot(); // Default setting

选项:在做出决定时测试人类或机器人的列表。默认为人。

Botdetector::detect()->useHumanData()->isBot(); // Defaults setting; Defaults to true
Botdetector::detect()->useHumanData(false)->isBot(); //Compares user-agent string against list of bots

选项:将空字符串或 null 设置为机器人或人。默认为机器人。

Botdetector::detect()->isNullBot()->isBot(); // Defaults setting; Defaults to true
Botdetector::detect()->isNullBot(false)->isBot(); //Empty string/null reported as human

函数也可以级联。例如

Botdetector::detect("user-agent-string")->addHumans(array('list','of','human','user-agent strings'))->ignoreDefaults()->useHumanData()->isNullBot()->isBot();
Botdetector::detect()->addBots(array('list','of','bot','user-agent strings'))->ignoreDefaults(false)->useHumanData(false)->isNullBot(false)->getBots();

初始发布版本 v0.9