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 = 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

Get the cookie value

Returns

string

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

The UNIX timestamp when the cookie Expires

Returns

mixed

setExpires()

setExpires(integer  $timestamp) 

Set the unix timestamp for which the cookie will expire

Parameters

integer $timestamp

Unix timestamp

getSecure()

getSecure() : null|boolean

Get whether or not this is a secure cookie

Returns

null|boolean

setSecure()

setSecure(boolean  $secure) 

Set whether or not the cookie is secure

Parameters

boolean $secure

Set to true or false if secure

getDiscard()

getDiscard() : null|boolean

Get whether or not this is a session cookie

Returns

null|boolean

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) : boolean

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

boolean

matchesDomain()

matchesDomain(string  $domain) : boolean

Check if the cookie matches a domain value

Parameters

string $domain

Domain to check against

Returns

boolean

isExpired()

isExpired() : boolean

Check if the cookie is expired

Returns

boolean

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