PHP code example of makm / flood-control

1. Go to this page and download the library: Download makm/flood-control 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/ */

    

makm / flood-control example snippets


$redis  = new \Redis();
$redis->connect('localhost');
$provider = new \Makm\FloodControl\AttemptProvider($redis);
$floodControl = new \Makm\FloodControl\FloodControl(
$provider,
[
    ['period' => \Makm\FloodControl\Limitations::PERIOD_WEEK, 'amount' => 5, 'times' => 15, 'sms-code'],
    ['period' => \Makm\FloodControl\Limitations::PERIOD_WEEK, 'amount' => 3, 'times' => 3, 'mail'],
    ['period' => \Makm\FloodControl\Limitations::PERIOD_DAY, 'amount' => 3, 'times' => 10, 'sms-code'],
    ['period' => \Makm\FloodControl\Limitations::PERIOD_DAY, 'amount' => 1, 'times' => 2, 'mail'],
    ['period' => \Makm\FloodControl\Limitations::PERIOD_MONTH, 'amount' => 1, 'times' => 200, 'sms-code'],
]);

$result = $floodControl->doAttempt(new Action('sms-code', '+155555555'));

$result = $floodControl->allow(new Action('mail', '+155555555'));