I ran into this issue today. I have a webform i created that restricts submissions to once daily. The client was testing the form only to find that after running through the submission once others in the same office couldnt submit any more entries. I went ahead an checked the use cookies option and it had no effect.

Digging into the module i found this method

function _webform_submission_limit_check($node) {
  global $user;

  // Check if submission limiting is enabled.
  if ($node->webform['submit_limit'] == '-1') {
    return FALSE; // No check enabled.
  }

  // Retrieve submission data for this IP address or username from the database.
  $query = 'SELECT count(*) '.
           'FROM {webform_submissions} '.
           "WHERE (( 0 = %d AND remote_addr = '%s') OR (uid > 0 AND uid = %d)) ".
           'AND submitted > %d AND nid = %d';

  // Fetch all the entries from the database within the submit interval with this username and IP.
  $num_submissions_database = db_result(db_query($query, $user->uid, ip_address(), $user->uid, ($node->webform['submit_interval'] != -1) ? (time() - $node->webform['submit_interval']) : $node->webform['submit_interval'], $node->nid));

  // Double check the submission history from the users machine using cookies.
  $num_submissions_cookie = 0;
  if ($user->uid == 0 && variable_get('webform_use_cookies', 0)) {
    $cookie_name = 'webform-'. $node->nid;

    if (isset($_COOKIE[$cookie_name]) && is_array($_COOKIE[$cookie_name])) {
      foreach ($_COOKIE[$cookie_name] as $key => $timestamp) {
        if ($timestamp <= time() - $node->webform['submit_interval']) {
          // Remove the cookie if past the required time interval.
          setcookie($cookie_name .'['. $key .']', '', 0);
        }
      }
      // Count the number of submissions recorded in cookies.
      $num_submissions_cookie = count($_COOKIE[$cookie_name]);
    }
    else {
      $num_submissions_cookie = 0;
    }
  }

  if ($num_submissions_database >= $node->webform['submit_limit'] || $num_submissions_cookie >= $node->webform['submit_limit']) {
    // Limit exceeded.
    return TRUE;
  }

  // Limit not exceeded.
  return FALSE;
}

I'm assuming this is where the problem is?
Looking at this bit

  if ($user->uid == 0 && variable_get('webform_use_cookies', 0)) {
    $cookie_name = 'webform-'. $node->nid;

Doest this mean that if the user is the admin AND the use cookies option was true THEN it retrieves the cookies?

also here:

  if ($num_submissions_database >= $node->webform['submit_limit'] || $num_submissions_cookie >= $node->webform['submit_limit']) {
    // Limit exceeded.
    return TRUE;
  }

Does this basically bypass the submission count in the cookie altogether? Since the multiple users from the same network would have the same ip address wouldnt we obviously get back multiple submissions from the DB ( assuming that multiple users submitted today) and prevent others from the same network from submitting?

Comments

malukalu’s picture

ok so i assumed in correctly about this bit

if ($user->uid == 0 && variable_get('webform_use_cookies', 0)) {
    $cookie_name = 'webform-'. $node->nid;

UID = 0 when the user is anonymous so that seems to make sense then ( meaning check the cookie if the user is anonymous and cookie option is set)

The latter bit still doesnt make sense to me thought...

quicksketch’s picture

Status: Active » Closed (duplicate)