function flood_is_allowed

cis7 common.inc flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)
cle7 common.inc flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)
elmsmedia7 common.inc flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)
icor7 common.inc flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)
meedjum_blog7 common.inc flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)
mooc7 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.

Parameters

$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.

5 calls to flood_is_allowed()
contact_personal_form in modules/contact/contact.pages.inc
Form constructor for the personal contact form.
contact_site_form in modules/contact/contact.pages.inc
Form constructor for the site-wide contact form.
devel_init in sites/all/modules/ulmus/devel/devel.module
Implementation of hook_init().
email_mail_page in sites/all/modules/ulmus/email/email.module
The contact form page.
user_login_authenticate_validate in modules/user/user.module
A validate handler on the login form. Check supplied username/password against local users table. If successful, $form_state['uid'] is set to the matching user ID.

File

includes/common.inc, line 1298
Common functions that many Drupal modules will need to reference.

Code

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,
  ))->fetchField();
  return ($number < $threshold);
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.