Let say you want to block some from bruteforcing some page.
Brute force protection
PHP
require_once($_path["modules"]."attempts.php");if(System_Module_attempts::active()) //optional validation to see if module is active (i.e. table exists)
{
$key="bf ".$_SERVER["REMOTE_ADDR"]; //generate a unique key (in this case based on the IP)
if(!System_Module_attempts::check($key, 5)) //check if the IP has knocked on the door more than 5 times
{
print "You ain't welcome here anymore!";
exit;
}
}
Alternatively you want to restrict a user to only view something every 2 minutes
Time restriction
PHP
$key="tr ".$_config->get("usernr"); //generate a unique key (in this case based on the user's ID)if(!System_Module_attempts::check($key, 1, 120)) //check if the user has viewed the page in the last 120 seconds
{
print "That's enough of that";
exit;
}
}