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() : mixed

Returns

mixed —

getName()

getName() : string

Get the cookie name

Returns

string —

setName()

setName(string  $name) : mixed

Set the cookie name

Parameters

string $name

Cookie name

Returns

mixed —

getValue()

getValue() : string

Get the cookie value

Returns

string —

setValue()

setValue(string  $value) : mixed

Set the cookie value

Parameters

string $value

Cookie value

Returns

mixed —

getDomain()

getDomain() : string|null

Get the domain

Returns

string|null —

setDomain()

setDomain(string  $domain) : mixed

Set the domain of the cookie

Parameters

string $domain

Returns

mixed —

getPath()

getPath() : string

Get the path

Returns

string —

setPath()

setPath(string  $path) : mixed

Set the path of the cookie

Parameters

string $path

Path of the cookie

Returns

mixed —

getMaxAge()

getMaxAge() : int|null

Maximum lifetime of the cookie in seconds

Returns

int|null —

setMaxAge()

setMaxAge(int  $maxAge) : mixed

Set the max-age of the cookie

Parameters

int $maxAge

Max age of the cookie in seconds

Returns

mixed —

getExpires()

getExpires() : mixed

The UNIX timestamp when the cookie Expires

Returns

mixed —

setExpires()

setExpires(int  $timestamp) : mixed

Set the unix timestamp for which the cookie will expire

Parameters

int $timestamp

Unix timestamp

Returns

mixed —

getSecure()

getSecure() : bool|null

Get whether or not this is a secure cookie

Returns

bool|null —

setSecure()

setSecure(bool  $secure) : mixed

Set whether or not the cookie is secure

Parameters

bool $secure

Set to true or false if secure

Returns

mixed —

getDiscard()

getDiscard() : bool|null

Get whether or not this is a session cookie

Returns

bool|null —

setDiscard()

setDiscard(bool  $discard) : mixed

Set whether or not this is a session cookie

Parameters

bool $discard

Set to true or false if this is a session cookie

Returns

mixed —

getHttpOnly()

getHttpOnly() : bool

Get whether or not this is an HTTP only cookie

Returns

bool —

setHttpOnly()

setHttpOnly(bool  $httpOnly) : mixed

Set whether or not this is an HTTP only cookie

Parameters

bool $httpOnly

Set to true or false if this is HTTP only

Returns

mixed —

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