You are here

public static function Helper::apbct_cookie__set in Anti Spam by CleanTalk 8.4

Same name and namespace in other branches
  1. 9.1.x src/lib/Cleantalk/Common/Helper.php \Cleantalk\Common\Helper::apbct_cookie__set()

Universal method to adding cookies

Parameters

$name:

string $value:

int $expires:

string $path:

null $domain:

bool $secure:

bool $httponly:

string $samesite:

Return value

void

File

src/lib/Cleantalk/Common/Helper.php, line 1102

Class

Helper
CleanTalk Helper class. Compatible with any CMS.

Namespace

Cleantalk\Common

Code

public static function apbct_cookie__set($name, $value = '', $expires = 0, $path = '', $domain = null, $secure = false, $httponly = false, $samesite = 'Lax') {

  // For PHP 7.3+ and above
  if (version_compare(phpversion(), '7.3.0', '>=')) {
    $params = array(
      'expires' => $expires,
      'path' => $path,
      'domain' => $domain,
      'secure' => $secure,
      'httponly' => $httponly,
    );
    if ($samesite) {
      $params['samesite'] = $samesite;
    }
    setcookie($name, $value, $params);

    // For PHP 5.6 - 7.2
  }
  else {
    setcookie($name, $value, $expires, $path, $domain, $secure, $httponly);
  }
}