class Cookie

Represents a cookie.

Constants

SAMESITE_LAX

SAMESITE_STRICT

Properties

protected $name
protected $value
protected $domain
protected $expire
protected $path
protected $secure
protected $httpOnly

Methods

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

Creates cookie from raw header string.

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

No description

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

No description

string
__toString()

Returns the cookie as a string.

string
getName()

Gets the name of the cookie.

string|null
getValue()

Gets the value of the cookie.

string|null
getDomain()

Gets the domain that the cookie is available to.

int
getExpiresTime()

Gets the time the cookie expires.

int
getMaxAge()

Gets the max-age attribute.

string
getPath()

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

bool
isSecure()

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

bool
isHttpOnly()

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

bool
isCleared()

Whether this cookie is about to be cleared.

bool
isRaw()

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

string|null
getSameSite()

Gets the SameSite attribute.

void
setSecureDefault(bool $default)

No description

Details

at line 43
static Cookie fromString(string $cookie, bool $decode = false)

Creates cookie from raw header string.

Parameters

string $cookie
bool $decode

Return Value

Cookie

at line 70
static Cookie create(string $name, string $value = null, $expire = 0, string|null $path = '/', string $domain = null, bool $secure = null, bool $httpOnly = true, bool $raw = false, string|null $sameSite = self::SAMESITE_LAX)

Parameters

string $name
string $value
$expire
string|null $path
string $domain
bool $secure
bool $httpOnly
bool $raw
string|null $sameSite

Return Value

Cookie

at line 88
__construct(string $name, string $value = null, int|string|DateTimeInterface $expire = 0, string|null $path = '/', string $domain = null, bool|null $secure = false, bool $httpOnly = true, bool $raw = false, string $sameSite = null)

Parameters

string $name The name of the cookie
string $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 $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 $sameSite Whether the cookie will be available for cross-site requests

Exceptions

InvalidArgumentException

at line 141
string __toString()

Returns the cookie as a string.

Return Value

string The cookie

at line 183
string getName()

Gets the name of the cookie.

Return Value

string

at line 193
string|null getValue()

Gets the value of the cookie.

Return Value

string|null

at line 203
string|null getDomain()

Gets the domain that the cookie is available to.

Return Value

string|null

at line 213
int getExpiresTime()

Gets the time the cookie expires.

Return Value

int

at line 223
int getMaxAge()

Gets the max-age attribute.

Return Value

int

at line 235
string getPath()

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

Return Value

string

at line 245
bool isSecure()

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

Return Value

bool

at line 255
bool isHttpOnly()

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

Return Value

bool

at line 265
bool isCleared()

Whether this cookie is about to be cleared.

Return Value

bool

at line 275
bool isRaw()

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

Return Value

bool

at line 285
string|null getSameSite()

Gets the SameSite attribute.

Return Value

string|null

at line 293
void setSecureDefault(bool $default)

Parameters

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

Return Value

void