You are here

public static function CleantalkFuncs::apbct_setcookie in Anti Spam by CleanTalk 8.3

Same name and namespace in other branches
  1. 8.4 src/CleantalkFuncs.php \Drupal\cleantalk\CleantalkFuncs::apbct_setcookie()
  2. 9.1.x src/CleantalkFuncs.php \Drupal\cleantalk\CleantalkFuncs::apbct_setcookie()

Save our variables into cookies OR sessions

Parameters

$name string Name of our variables to save:

$value string Value of our variables to save:

1 call to CleantalkFuncs::apbct_setcookie()
BootSubscriber::handle in src/EventSubscriber/BootSubscriber.php
Handles a Request to convert it to a Response.

File

src/CleantalkFuncs.php, line 41

Class

CleantalkFuncs
Cleantalk class create request

Namespace

Drupal\cleantalk

Code

public static function apbct_setcookie($name, $value) {
  if (\Drupal::config('cleantalk.settings')
    ->get('cleantalk_alternative_cookies_session')) {
    self::_apbct_alt_sessions__remove_old();

    // Into database
    $connection = \Drupal::database();
    $connection
      ->query("INSERT INTO {cleantalk_sessions}\n      (id, name, value, last_update)\n      VALUES (:id, :name, :value, :last_update)\n      ON DUPLICATE KEY UPDATE\n      value = :value,\n      last_update = :last_update", array(
      ':id' => self::_apbct_alt_session__id__get(),
      ':name' => $name,
      ':value' => $value,
      ':last_update' => date('Y-m-d H:i:s'),
    ));
  }
  else {

    // Into cookies
    setcookie($name, $value, 0, '/');
  }
}