Properties

$defaults

$defaults : array

Type

array

$data

$data : array

Type

array — Cookie data

Methods

fromString()

fromString(string  $cookie) : self

Create a new SetCookie object from a string.

Parameters

string $cookie

Set-Cookie header string

Returns

self —

__construct()

__construct(array  $data = []) : mixed

Parameters

array $data

Array of cookie data provided by a Cookie parser

Returns

mixed —

__toString()

__toString() : mixed

Returns

mixed —

toArray()

toArray() : array

Returns

array —

getName()

getName() : string

Get the cookie name.

Returns

string —

setName()

setName(string  $name) : void

Set the cookie name.

Parameters

string $name

Cookie name

getValue()

getValue() : string|null

Get the cookie value.

Returns

string|null —

setValue()

setValue(string  $value) : void

Set the cookie value.

Parameters

string $value

Cookie value

getDomain()

getDomain() : string|null

Get the domain.

Returns

string|null —

setDomain()

setDomain(string  $domain) : void

Set the domain of the cookie.

Parameters

string $domain

getPath()

getPath() : string

Get the path.

Returns

string —

setPath()

setPath(string  $path) : void

Set the path of the cookie.

Parameters

string $path

Path of the cookie

getMaxAge()

getMaxAge() : int|null

Maximum lifetime of the cookie in seconds.

Returns

int|null —

setMaxAge()

setMaxAge(int  $maxAge) : void

Set the max-age of the cookie.

Parameters

int $maxAge

Max age of the cookie in seconds

getExpires()

getExpires() : string|int|null

The UNIX timestamp when the cookie Expires.

Returns

string|int|null —

setExpires()

setExpires(int|string  $timestamp) : void

Set the unix timestamp for which the cookie will expire.

Parameters

int|string $timestamp

Unix timestamp or any English textual datetime description.

getSecure()

getSecure() : bool|null

Get whether or not this is a secure cookie.

Returns

bool|null —

setSecure()

setSecure(bool  $secure) : void

Set whether or not the cookie is secure.

Parameters

bool $secure

Set to true or false if secure

getDiscard()

getDiscard() : bool|null

Get whether or not this is a session cookie.

Returns

bool|null —

setDiscard()

setDiscard(bool  $discard) : void

Set whether or not this is a session cookie.

Parameters

bool $discard

Set to true or false if this is a session cookie

getHttpOnly()

getHttpOnly() : bool

Get whether or not this is an HTTP only cookie.

Returns

bool —

setHttpOnly()

setHttpOnly(bool  $httpOnly) : void

Set whether or not this is an HTTP only cookie.

Parameters

bool $httpOnly

Set to true or false if this is HTTP only

matchesPath()

matchesPath(string  $requestPath) : bool

Check if the cookie matches a path value.

A request-path path-matches a given cookie-path if at least one of the following conditions holds:

  • The cookie-path and the request-path are identical.
  • The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").
  • The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie- path is a %x2F ("/") character.

Parameters

string $requestPath

Path to check against

Returns

bool —

matchesDomain()

matchesDomain(string  $domain) : bool

Check if the cookie matches a domain value.

Parameters

string $domain

Domain to check against

Returns

bool —

isExpired()

isExpired() : bool

Check if the cookie is expired.

Returns

bool —

validate()

validate() : bool|string

Check if the cookie is valid according to RFC 6265.

Returns

bool|string —

Returns true if valid or an error message if invalid