1. Go to this page and download the library: Download webiik/attempts 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/ */
webiik / attempts example snippets
// Instatiate Attempts
$attempts = new \Webiik\Attempts\Attempts();
// Set storage (you have to write your own storage)
$attempts->setStorage(function() {
return new \Webiik\Attempts\YourCustomStorage();
});
// Store user login attempt
$attempts->write('login', $attempts->getIp());
// Get user login attempts within the last hour
$startTimestamp = time() - 60 * 60;
$loginAttempts = $attempts->readByIp('login', $attempts->getIp(), $startTimestamp);
if(count($loginAttempts) > 10) {
// E.g. Temporary prevent user to log in
}
// Delete expired login attempts with probability 2/100
$attempts->delete('login', $startTimestamp, 2);
setStorage(callable $factory): void
$attempts->setStorage(function() {
return new \Webiik\Attempts\YourCustomStorage();
});