1 common.inc flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)

Checks whether a user is allowed to proceed with the specified event.

Events can have thresholds saying that each user can only do that event a certain number of times in a time window. This function verifies that the current user has not exceeded this threshold.


$name: The unique name of the event.

$threshold: The maximum number of times each user can do this event per time window.

$window: Number of seconds in the time window for this event (default is 3600 seconds, or 1 hour).

$identifier: Unique identifier of the current user. Defaults to their IP address.

Return value

TRUE if the user is allowed to proceed. FALSE if they have exceeded the threshold and should not be allowed to proceed.


core/includes/common.inc, line 1548
Common functions that many Backdrop modules will need to reference.


function flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL) {
  if (!isset($identifier)) {
    $identifier = ip_address();
  $number = db_query("SELECT COUNT(*) FROM {flood} WHERE event = :event AND identifier = :identifier AND timestamp > :timestamp", array(
    ':event' => $name,
    ':identifier' => $identifier,
    ':timestamp' => REQUEST_TIME - $window))
  return ($number < $threshold);