jqqjj / simple-anti-robot
用于保护您的应用程序远离机器人的简单API
1.0.1
2020-01-08 10:02 UTC
Requires
- php: >=5.3
This package is auto-updated.
Last update: 2024-09-08 20:54:30 UTC
README
用于保护您的应用程序远离机器人的简单API。
安装
运行以下命令以通过Composer包含此包
composer require jqqjj/simple-anti-robot
用法
创建mysql表(当使用DBTableGateway适配器时)
CREATE TABLE `simple_anti_robot_sessions` ( `session_id` char(32) NOT NULL, `remaining` int(10) unsigned DEFAULT NULL, `expired_time` timestamp NULL DEFAULT NULL, PRIMARY KEY (`session_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `simple_anti_robot_attempts` ( `session_id` char(32) NOT NULL, `status` tinyint(3) unsigned NOT NULL, `add_time` timestamp NULL DEFAULT NULL, `ip` char(15) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
代码
use Jqqjj\SimpleAntiRobot\Manager; use Jqqjj\SimpleAntiRobot\Adapter\DBTableGateway; //Create a PDO object $pdo = new \PDO('mysql:host=localhost;port=3306;dbname=yourdbname','dbuser','dbpasswd'); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); //Create an adapter(Only MySQL adapter is supported Currently) $adapter = new DBTableGateway($pdo); $object = new Manager($adapter); //Run the codes when the client do something incorrectly $object->attemptFailure(); //Run the codes when the client do things as you want to be $object->attemptSuccess(); //Check it, it will return false when the client is a robot if($object->isHuman()){ //human } if($object->isRobot()){ //robot } //Finally, output the cookie $object->outputCookie(); //OR header("Set-Cookie:".$object->getOutputCookieString());
许可证
本软件包遵循MIT许可证。