Constants

SAMESITE_NONE

SAMESITE_NONE = 'none'

SAMESITE_LAX

SAMESITE_LAX = 'lax'

SAMESITE_STRICT

SAMESITE_STRICT = 'strict'

RESERVED_CHARS_LIST

RESERVED_CHARS_LIST = "=,; \t\r\n\v\f"

RESERVED_CHARS_FROM

RESERVED_CHARS_FROM = ['=', ',', ';', ' ', "\t", "\r", "\n", "\v", "\f"]

RESERVED_CHARS_TO

RESERVED_CHARS_TO = ['%3D', '%2C', '%3B', '%20', '%09', '%0D', '%0A', '%0B', '%0C']

Properties

$name

$name

$value

$value

$domain

$domain

$expire

$expire

$path

$path

$secure

$secure

$httpOnly

$httpOnly

$raw

$raw

$sameSite

$sameSite

$secureDefault

$secureDefault

Methods

fromString()

fromString(string  $cookie, bool  $decode = false) : static

Creates cookie from raw header string.

Parameters

string $cookie
bool $decode

Returns

static —

create()

create(string  $name, string  $value = null, mixed  $expire, ?string  $path = '/', string  $domain = null, bool  $secure = null, bool  $httpOnly = true, bool  $raw = false, ?string  $sameSite = self::SAMESITE_LAX) : self

Parameters

string $name
string $value
mixed $expire
?string $path
string $domain
bool $secure
bool $httpOnly
bool $raw
?string $sameSite

Returns

self —

__construct()

__construct(string  $name, string|null  $value = null, int|string|\DateTimeInterface  $expire, string|null  $path = '/', string|null  $domain = null, bool|null  $secure = null, bool  $httpOnly = true, bool  $raw = false, string|null  $sameSite = 'lax') : mixed

Parameters

string $name

The name of the cookie

string|null $value

The value of the cookie

int|string|\DateTimeInterface $expire

The time the cookie expires

string|null $path

The path on the server in which the cookie will be available on

string|null $domain

The domain that the cookie is available to

bool|null $secure

Whether the client should send back the cookie only over HTTPS or null to auto-enable this when the request is already using HTTPS

bool $httpOnly

Whether the cookie will be made accessible only through the HTTP protocol

bool $raw

Whether the cookie value should be sent with no url encoding

string|null $sameSite

Whether the cookie will be available for cross-site requests

Throws

\InvalidArgumentException

Returns

mixed —

withValue()

withValue(?string  $value) : static

Creates a cookie copy with a new value.

Parameters

?string $value

Returns

static —

withDomain()

withDomain(?string  $domain) : static

Creates a cookie copy with a new domain that the cookie is available to.

Parameters

?string $domain

Returns

static —

withExpires()

withExpires(int|string|\DateTimeInterface  $expire) : static

Creates a cookie copy with a new time the cookie expires.

Parameters

int|string|\DateTimeInterface $expire

Returns

static —

withPath()

withPath(string  $path) : static

Creates a cookie copy with a new path on the server in which the cookie will be available on.

Parameters

string $path

Returns

static —

withSecure()

withSecure(bool  $secure = true) : static

Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client.

Parameters

bool $secure

Returns

static —

withHttpOnly()

withHttpOnly(bool  $httpOnly = true) : static

Creates a cookie copy that be accessible only through the HTTP protocol.

Parameters

bool $httpOnly

Returns

static —

withRaw()

withRaw(bool  $raw = true) : static

Creates a cookie copy that uses no url encoding.

Parameters

bool $raw

Returns

static —

withSameSite()

withSameSite(?string  $sameSite) : static

Creates a cookie copy with SameSite attribute.

Parameters

?string $sameSite

Returns

static —

__toString()

__toString() : string

Returns the cookie as a string.

Returns

string —

getName()

getName() : string

Gets the name of the cookie.

Returns

string —

getValue()

getValue() : string|null

Gets the value of the cookie.

Returns

string|null —

getDomain()

getDomain() : string|null

Gets the domain that the cookie is available to.

Returns

string|null —

getExpiresTime()

getExpiresTime() : int

Gets the time the cookie expires.

Returns

int —

getMaxAge()

getMaxAge() : int

Gets the max-age attribute.

Returns

int —

getPath()

getPath() : string

Gets the path on the server in which the cookie will be available on.

Returns

string —

isSecure()

isSecure() : bool

Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.

Returns

bool —

isHttpOnly()

isHttpOnly() : bool

Checks whether the cookie will be made accessible only through the HTTP protocol.

Returns

bool —

isCleared()

isCleared() : bool

Whether this cookie is about to be cleared.

Returns

bool —

isRaw()

isRaw() : bool

Checks if the cookie value should be sent with no url encoding.

Returns

bool —

getSameSite()

getSameSite() : string|null

Gets the SameSite attribute.

Returns

string|null —

setSecureDefault()

setSecureDefault(bool  $default) : void

Parameters

bool $default

The default value of the "secure" flag when it is set to null

expiresTimestamp()

expiresTimestamp(int|string|\DateTimeInterface  $expire) : int

Converts expires formats to a unix timestamp.

Parameters

int|string|\DateTimeInterface $expire

Returns

int —