SetCookie
in package
Set-Cookie object
Table of Contents
Properties
Methods
- __construct() : mixed
- __toString() : mixed
- fromString() : self
- Create a new SetCookie object from a string.
- getDiscard() : bool|null
- Get whether or not this is a session cookie.
- getDomain() : string|null
- Get the domain.
- getExpires() : string|int|null
- The UNIX timestamp when the cookie Expires.
- getHttpOnly() : bool
- Get whether or not this is an HTTP only cookie.
- getMaxAge() : int|null
- Maximum lifetime of the cookie in seconds.
- getName() : string
- Get the cookie name.
- getPath() : string
- Get the path.
- getSecure() : bool
- Get whether or not this is a secure cookie.
- getValue() : string|null
- Get the cookie value.
- isExpired() : bool
- Check if the cookie is expired.
- matchesDomain() : bool
- Check if the cookie matches a domain value.
- matchesPath() : bool
- Check if the cookie matches a path value.
- setDiscard() : void
- Set whether or not this is a session cookie.
- setDomain() : void
- Set the domain of the cookie.
- setExpires() : void
- Set the unix timestamp for which the cookie will expire.
- setHttpOnly() : void
- Set whether or not this is an HTTP only cookie.
- setMaxAge() : void
- Set the max-age of the cookie.
- setName() : void
- Set the cookie name.
- setPath() : void
- Set the path of the cookie.
- setSecure() : void
- Set whether or not the cookie is secure.
- setValue() : void
- Set the cookie value.
- toArray() : array<string|int, mixed>
- validate() : bool|string
- Check if the cookie is valid according to RFC 6265.
Properties
$data
private
array<string|int, mixed>
$data
Cookie data
$defaults
private
static array<string|int, mixed>
$defaults
= ['Name' => null, 'Value' => null, 'Domain' => null, 'Path' => '/', 'Max-Age' => null, 'Expires' => null, 'Secure' => false, 'Discard' => false, 'HttpOnly' => false]
Methods
__construct()
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string|int, mixed> = []
-
Array of cookie data provided by a Cookie parser
__toString()
public
__toString() : mixed
fromString()
Create a new SetCookie object from a string.
public
static fromString(string $cookie) : self
Parameters
- $cookie : string
-
Set-Cookie header string
Return values
selfgetDiscard()
Get whether or not this is a session cookie.
public
getDiscard() : bool|null
Return values
bool|nullgetDomain()
Get the domain.
public
getDomain() : string|null
Return values
string|nullgetExpires()
The UNIX timestamp when the cookie Expires.
public
getExpires() : string|int|null
Return values
string|int|nullgetHttpOnly()
Get whether or not this is an HTTP only cookie.
public
getHttpOnly() : bool
Return values
boolgetMaxAge()
Maximum lifetime of the cookie in seconds.
public
getMaxAge() : int|null
Return values
int|nullgetName()
Get the cookie name.
public
getName() : string
Return values
stringgetPath()
Get the path.
public
getPath() : string
Return values
stringgetSecure()
Get whether or not this is a secure cookie.
public
getSecure() : bool
Return values
boolgetValue()
Get the cookie value.
public
getValue() : string|null
Return values
string|nullisExpired()
Check if the cookie is expired.
public
isExpired() : bool
Return values
boolmatchesDomain()
Check if the cookie matches a domain value.
public
matchesDomain(string $domain) : bool
Parameters
- $domain : string
-
Domain to check against
Return values
boolmatchesPath()
Check if the cookie matches a path value.
public
matchesPath(string $requestPath) : bool
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
- $requestPath : string
-
Path to check against
Return values
boolsetDiscard()
Set whether or not this is a session cookie.
public
setDiscard(bool $discard) : void
Parameters
- $discard : bool
-
Set to true or false if this is a session cookie
setDomain()
Set the domain of the cookie.
public
setDomain(string|null $domain) : void
Parameters
- $domain : string|null
setExpires()
Set the unix timestamp for which the cookie will expire.
public
setExpires(int|string|null $timestamp) : void
Parameters
- $timestamp : int|string|null
-
Unix timestamp or any English textual datetime description.
setHttpOnly()
Set whether or not this is an HTTP only cookie.
public
setHttpOnly(bool $httpOnly) : void
Parameters
- $httpOnly : bool
-
Set to true or false if this is HTTP only
setMaxAge()
Set the max-age of the cookie.
public
setMaxAge(int|null $maxAge) : void
Parameters
- $maxAge : int|null
-
Max age of the cookie in seconds
setName()
Set the cookie name.
public
setName(string $name) : void
Parameters
- $name : string
-
Cookie name
setPath()
Set the path of the cookie.
public
setPath(string $path) : void
Parameters
- $path : string
-
Path of the cookie
setSecure()
Set whether or not the cookie is secure.
public
setSecure(bool $secure) : void
Parameters
- $secure : bool
-
Set to true or false if secure
setValue()
Set the cookie value.
public
setValue(string $value) : void
Parameters
- $value : string
-
Cookie value
toArray()
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>validate()
Check if the cookie is valid according to RFC 6265.
public
validate() : bool|string
Return values
bool|string —Returns true if valid or an error message if invalid