function shurly_flood_is_allowed in ShURLy 8
Same name and namespace in other branches
- 6 shurly.module \shurly_flood_is_allowed()
- 7 shurly.module \shurly_flood_is_allowed()
Function to check if the current user is in the flood table.
1 call to shurly_flood_is_allowed()
- shurly_rate_limit_allowed in ./
shurly.module - Check rate limit for this user return an array in the following format array( 'allowed' => TRUE/FALSE 'rate' => number of requests allowed 'time' => period of time in minutes )
File
- ./
shurly.module, line 105 - Description http://www.youtube.com/watch?v=Qo7qoonzTCE.
Code
function shurly_flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL) {
if (!isset($identifier)) {
$identifier = \Drupal::request()
->getClientIp();
}
$request_time = \Drupal::time()
->getRequestTime();
$number = \Drupal::database()
->query("SELECT COUNT(*) FROM {shurly_flood} WHERE event = :event AND identifier = :identifier AND timestamp > :timestamp", [
'event' => $name,
'identifier' => $identifier,
'timestamp' => $request_time - $window,
])
->fetchField();
return $number < $threshold;
}