Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Cookie.php

function Cookie::__construct

Same name in this branch
  1. 11.1.x vendor/symfony/http-foundation/Cookie.php \Symfony\Component\HttpFoundation\Cookie::__construct()
  2. 11.1.x core/modules/user/src/Authentication/Provider/Cookie.php \Drupal\user\Authentication\Provider\Cookie::__construct()

Sets a cookie.

Parameters

string $name The cookie name:

string|null $value The value of the cookie:

string|null $expires The time the cookie expires:

string|null $path The path on the server in which the cookie will be available on:

string $domain The domain that the cookie is available:

bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client:

bool $httponly The cookie httponly flag:

bool $encodedValue Whether the value is encoded or not:

string|null $samesite The cookie samesite attribute:

File

vendor/symfony/browser-kit/Cookie.php, line 56

Class

Cookie
Cookie represents an HTTP cookie.

Namespace

Symfony\Component\BrowserKit

Code

public function __construct(string $name, ?string $value, ?string $expires = null, ?string $path = null, string $domain = '', bool $secure = false, bool $httponly = true, bool $encodedValue = false, ?string $samesite = null) {
    if ($encodedValue) {
        $this->rawValue = $value ?? '';
        $this->value = urldecode($this->rawValue);
    }
    else {
        $this->value = $value ?? '';
        $this->rawValue = rawurlencode($this->value);
    }
    $this->path = $path ?: '/';
    if (null !== $expires) {
        $timestampAsDateTime = \DateTimeImmutable::createFromFormat('U', $expires);
        if (false === $timestampAsDateTime) {
            throw new UnexpectedValueException(\sprintf('The cookie expiration time "%s" is not valid.', $expires));
        }
        $this->expires = $timestampAsDateTime->format('U');
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal