PHP code example of vincendev / laraflood

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

    

vincendev / laraflood example snippets



Laraflood::check( $identity = 'ip', $action = 'default', $maxAttempts = 5, $minutes = 5 );
Laraflood::check();
Laraflood::check( $user->id , 'submit-comment');
Laraflood::check( $user->id , 'report-comment', 1, 5);

/* Return bool */


Laraflood::checkOnly( $identity = 'ip', $action = 'default', $maxAttempts = 5, $minutes = 5 );
Laraflood::checkOnly();
Laraflood::checkOnly( $user->id , 'submit-comment');
Laraflood::checkOnly( $user->id , 'report-comment', 1, 5);

/* Return bool */


Laraflood::addAttempt( $identity = 'ip', $action = 'default', $minutes = 5 );
Laraflood::addAttempt();
Laraflood::addAttempt('ip', 'like-post');
Laraflood::addAttempt( $user->id ,'default', 5 );

/* Void */



Laraflood::timeLeft( $identity = 'ip', $action = 'default');
Laraflood::timeLeft();
Laraflood::timeLeft( 'ip', 'like-post');

/* Return string */
	# X hours
	# X minutes
	# X seconds





Laraflood::get($identity = 'ip', $action = 'default')
Laraflood::get();
Laraflood::get( 'ip', 'like-post');

/*
array:3 [▼
  "action" => "default"
  "attempts" => 1
  "expiration" => "2019-09-18 19:51:01.175237"
]
*/


public function postLogin()
{
	
/**
* If thes user ip has >= 5 failed login attempts in last 5 minutes, redirect user
* back with error:
*/

	if( Laraflood::check( 'ip' , 'login', 5, 5 ) === FALSE )
		return redirect()->back()->withErrors(["AntiFlood Protection! Try again in ".Laraflood::timeLeft('ip','login')." ."]);
	
	/**
	* Your code here..
	*/

}

public function incrementPostViews()
{
		$action = "post-visit:" . $post->id; // Post unique ID
		$visitsPerUser = 1;
		$minutes = 1440; // 24Hours
        if(Laraflood::checkOnly('ip', $action, $visitsPerUser)){
			/**
			* Increment post views
			* Your code here..
			*/
			Laraflood::addAttempt('ip', $action, $minutes);
        }

}