Properties

$defaults

$defaults : array

Type

array

$data

$data : array

Type

array — Cookie data

Methods

fromString()

fromString(string  $cookie) 

Create a new SetCookie object from a string.

Parameters

string $cookie

Set-Cookie header string

__construct()

__construct(array  $data = array()) 

Parameters

array $data

Array of cookie data provided by a Cookie parser

__toString()

__toString() 

toArray()

toArray() 

getName()

getName() : string

Get the cookie name.

Returns

string

setName()

setName(string  $name) 

Set the cookie name.

Parameters

string $name

Cookie name

getValue()

getValue() : string|null

Get the cookie value.

Returns

string|null

setValue()

setValue(string  $value) 

Set the cookie value.

Parameters

string $value

Cookie value

getDomain()

getDomain() : string|null

Get the domain.

Returns

string|null

setDomain()

setDomain(string  $domain) 

Set the domain of the cookie.

Parameters

string $domain

getPath()

getPath() : string

Get the path.

Returns

string

setPath()

setPath(string  $path) 

Set the path of the cookie.

Parameters

string $path

Path of the cookie

getMaxAge()

getMaxAge() : integer|null

Maximum lifetime of the cookie in seconds.

Returns

integer|null

setMaxAge()

setMaxAge(integer  $maxAge) 

Set the max-age of the cookie.

Parameters

integer $maxAge

Max age of the cookie in seconds

getExpires()

getExpires() : string|integer|null

The UNIX timestamp when the cookie Expires.

Returns

string|integer|null

setExpires()

setExpires(integer|string  $timestamp) 

Set the unix timestamp for which the cookie will expire.

Parameters

integer|string $timestamp

Unix timestamp or any English textual datetime description.

getSecure()

getSecure() : boolean|null

Get whether or not this is a secure cookie.

Returns

boolean|null

setSecure()

setSecure(boolean  $secure) 

Set whether or not the cookie is secure.

Parameters

boolean $secure

Set to true or false if secure

getDiscard()

getDiscard() : boolean|null

Get whether or not this is a session cookie.

Returns

boolean|null

setDiscard()

setDiscard(boolean  $discard) 

Set whether or not this is a session cookie.

Parameters

boolean $discard

Set to true or false if this is a session cookie

getHttpOnly()

getHttpOnly() : boolean

Get whether or not this is an HTTP only cookie.

Returns

boolean

setHttpOnly()

setHttpOnly(boolean  $httpOnly) 

Set whether or not this is an HTTP only cookie.

Parameters

boolean $httpOnly

Set to true or false if this is HTTP only

matchesPath()

matchesPath(string  $requestPath) 

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

matchesDomain()

matchesDomain(string  $domain) 

Check if the cookie matches a domain value.

Parameters

string $domain

Domain to check against

isExpired()

isExpired() 

Check if the cookie is expired.

validate()

validate() : boolean|string

Check if the cookie is valid according to RFC 6265.

Returns

boolean|string —

Returns true if valid or an error message if invalid