You are here

public static function CleantalkFuncs::apbct_getcookie in Anti Spam by CleanTalk 9.1.x

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

Get our variables from cookies OR sessions

Parameters

$name string Name of necessary variable to get:

Return value

string|null

7 calls to CleantalkFuncs::apbct_getcookie()
AntiCrawler::check in src/lib/Cleantalk/Common/Firewall/Modules/AntiCrawler.php
Use this method to execute main logic of the module.
AntiFlood::check in src/lib/Cleantalk/Common/Firewall/Modules/AntiFlood.php
Use this method to execute main logic of the module.
BootSubscriber::handle in src/EventSubscriber/BootSubscriber.php
CleantalkFuncs::_cleantalk_apbct_cookies_test in src/CleantalkFuncs.php
Cookie test
CleantalkFuncs::_cleantalk_check_spam in src/CleantalkFuncs.php
Cleantalk inner function - performs antispam checking.

... See full list

File

src/CleantalkFuncs.php, line 112

Class

CleantalkFuncs
Cleantalk class create request

Namespace

Drupal\cleantalk

Code

public static function apbct_getcookie($name) {
  if (\Drupal::config('cleantalk.settings')
    ->get('cleantalk_set_cookies')) {
    if (\Drupal::config('cleantalk.settings')
      ->get('cleantalk_alternative_cookies_session') && substr($name, 0, strlen('apbct')) === 'apbct') {

      // From database
      $connection = \Drupal::database();
      $value = $connection
        ->query("SELECT value FROM {cleantalk_sessions} WHERE id = :id AND name = :name", array(
        ':id' => self::_apbct_alt_session__id__get(),
        ':name' => $name,
      ))
        ->fetchField();
      if (false !== $value) {
        return $value;
      }
      else {
        return null;
      }
    }
    else {

      // From cookies
      if (isset($_COOKIE[$name])) {
        return $_COOKIE[$name];
      }
      else {
        return null;
      }
    }
  }
  return null;
}