sinevia / php-library-throttle-plugin
限制资源访问的插件。
v1.4.0
2021-04-09 17:21 UTC
Requires
- php: >=5.4
- sinevia/php-library-sqldb: 3.*
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-10 00:38:27 UTC
README
一个限制资源(例如登录表单)访问的插件。限制基于在锁定访问指定时间段之前尝试的次数。
使用SQL后端(MySQL或SQLite)来跟踪对资源的访问尝试。
安装
- 通过Composer(首选)
composer require sinevia/php-library-throttle-plugin
- 手动安装
"repositories": [ { "type": "vcs", "url": "https://github.com/Sinevia/php-library-throttle-plugin.git" } ], "require": { "php": ">=5.5.9", "sinevia/php-library-throttle-plugin": "dev-master" },
如何使用?
\Sinevia\Plugins\ThrottlePlugin::configure([ 'pdo' => \DB::getPdo() ]); $userIp = \Sinevia\Plugins\ThrottlePlugin::getCurrentUserIp(); $mayAttempt = \Sinevia\Plugins\ThrottlePlugin::mayAttempt('LoginForm', $userIp, 6, 10 * 60); // 6 attempts in 10 minutes if ($mayAttempt == false) { $message = 'You have passed the maximum allowed authentication attempts.'; $message .= ' Please, check your password and try again in 10 minutes.'; return redirect()->back()->withErrors($message)->withInput(); }