1. Go to this page and download the library: Download acidf0x/laravel-ez-throttle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
acidf0x / laravel-ez-throttle example snippets
use AcidF0x\EzThrottle\Throttle;
$throttle = new Throttle();
// or
$throttle = new Throttle($throttleKey , $maxAttempts, $decayMinutes);
// increase hit count
$throttle->hit()
if ($throttle->isBlock()) {
echo $throttle->getErrorMsg(); // "Too Many Requests. Please try again in 1 minutes"
} else {
// ...
if ( ... ) {
$throttle->clear();
}
}
use AcidF0x\EzThrottle\Foundation\EzThrottle;
class SomeController extends Controller
{
use EzThrottle;
$protected $ThrottleKey = 'LoginThrottle';
$protected $maxAttempts = '3';
$protected $decayMinutes = '1';
public function doLogin()
{
//.....
// increase hit count
$this->hit()
if ($this->isBlock()) {
return $this->getErrorMsg(); // "Too Many Requests. Please try again in 1 minutes"
} else {
// ...
if ( ... ) {
$this->clear();
}
}
//......
}
}
# resources/lang/vendor/ezthrottle/en/error.php
return [
'sec'=> 'Too Many Requests. Please try again in :sec seconds',
'min'=> 'Too Many Requests. Please try again in :min minutes',
'hour'=> 'Too Many Requests. Please try again in :hour hours',
'days'=> 'Too Many Requests. Please try again in :day days',
];