You are here

public static function CleantalkFuncs::_cleantalk_apbct_cookies_set in Anti Spam by CleanTalk 7.4

Same name and namespace in other branches
  1. 7.5 src/CleantalkFuncs.php \CleantalkFuncs::_cleantalk_apbct_cookies_set()
1 call to CleantalkFuncs::_cleantalk_apbct_cookies_set()
cleantalk_init in ./cleantalk.module
Implements hook_init()

File

src/CleantalkFuncs.php, line 26

Class

CleantalkFuncs
Cleantalk class create request

Code

public static function _cleantalk_apbct_cookies_set() {

  // If Cookies are disabled
  if (!variable_get('cleantalk_set_cookies', 1)) {
    return;
  }

  // If headers were sent
  if (headers_sent()) {
    return;
  }

  // Cookie names to validate
  $cookie_test_value = array(
    'cookies_names' => array(),
    'check_value' => trim(variable_get('cleantalk_authkey', '')),
  );

  // Submit time
  $apbct_timestamp = time();

  // Fix for submit_time = 0
  if (variable_get('cleantalk_alternative_cookies_session', 0)) {

    // by database
    $prev_time = self::_apbct_getcookie('apbct_prev_timestamp');
    if (is_null($prev_time)) {
      self::_apbct_setcookie('apbct_timestamp', $apbct_timestamp);
      self::_apbct_setcookie('apbct_prev_timestamp', $apbct_timestamp);
      $cookie_test_value['check_value'] .= $apbct_timestamp;
    }
    else {
      self::_apbct_setcookie('apbct_timestamp', $prev_time);
      self::_apbct_setcookie('apbct_prev_timestamp', $apbct_timestamp);
      $cookie_test_value['check_value'] .= $prev_time;
    }
  }
  else {

    // by cookies
    self::_apbct_setcookie('apbct_timestamp', $apbct_timestamp);
    $cookie_test_value['check_value'] .= $apbct_timestamp;
  }
  $cookie_test_value['cookies_names'][] = 'apbct_timestamp';

  //Previous referer
  if (!empty($_SERVER['HTTP_REFERER'])) {
    self::_apbct_setcookie('apbct_prev_referer', $_SERVER['HTTP_REFERER']);
    $cookie_test_value['cookies_names'][] = 'apbct_prev_referer';
    $cookie_test_value['check_value'] .= $_SERVER['HTTP_REFERER'];
  }

  // Cookies test
  $cookie_test_value['check_value'] = md5($cookie_test_value['check_value']);
  self::_apbct_setcookie('apbct_cookies_test', json_encode($cookie_test_value));
}