Documentation

SetCookie
in package

Set-Cookie object

Table of Contents

$data  : array<string|int, mixed>
$defaults  : array<string|int, mixed>
__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()  : mixed
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|null
Get whether or not this is a secure cookie
getValue()  : string
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()  : mixed
Set whether or not this is a session cookie
setDomain()  : mixed
Set the domain of the cookie
setExpires()  : mixed
Set the unix timestamp for which the cookie will expire
setHttpOnly()  : mixed
Set whether or not this is an HTTP only cookie
setMaxAge()  : mixed
Set the max-age of the cookie
setName()  : mixed
Set the cookie name
setPath()  : mixed
Set the path of the cookie
setSecure()  : mixed
Set whether or not the cookie is secure
setValue()  : mixed
Set the cookie value
toArray()  : mixed
validate()  : bool|string
Check if the cookie is valid according to RFC 6265

Properties

$data

private array<string|int, mixed> $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

Return values
mixed

__toString()

public __toString() : mixed
Return values
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
self

getDiscard()

Get whether or not this is a session cookie

public getDiscard() : bool|null
Return values
bool|null

getDomain()

Get the domain

public getDomain() : string|null
Return values
string|null

getExpires()

The UNIX timestamp when the cookie Expires

public getExpires() : mixed
Return values
mixed

getHttpOnly()

Get whether or not this is an HTTP only cookie

public getHttpOnly() : bool
Return values
bool

getMaxAge()

Maximum lifetime of the cookie in seconds

public getMaxAge() : int|null
Return values
int|null

getName()

Get the cookie name

public getName() : string
Return values
string

getPath()

Get the path

public getPath() : string
Return values
string

getSecure()

Get whether or not this is a secure cookie

public getSecure() : bool|null
Return values
bool|null

getValue()

Get the cookie value

public getValue() : string
Return values
string

isExpired()

Check if the cookie is expired

public isExpired() : bool
Return values
bool

matchesDomain()

Check if the cookie matches a domain value

public matchesDomain(string $domain) : bool
Parameters
$domain : string

Domain to check against

Return values
bool

matchesPath()

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
bool

setDiscard()

Set whether or not this is a session cookie

public setDiscard(bool $discard) : mixed
Parameters
$discard : bool

Set to true or false if this is a session cookie

Return values
mixed

setDomain()

Set the domain of the cookie

public setDomain(string $domain) : mixed
Parameters
$domain : string
Return values
mixed

setExpires()

Set the unix timestamp for which the cookie will expire

public setExpires(int $timestamp) : mixed
Parameters
$timestamp : int

Unix timestamp

Return values
mixed

setHttpOnly()

Set whether or not this is an HTTP only cookie

public setHttpOnly(bool $httpOnly) : mixed
Parameters
$httpOnly : bool

Set to true or false if this is HTTP only

Return values
mixed

setMaxAge()

Set the max-age of the cookie

public setMaxAge(int $maxAge) : mixed
Parameters
$maxAge : int

Max age of the cookie in seconds

Return values
mixed

setName()

Set the cookie name

public setName(string $name) : mixed
Parameters
$name : string

Cookie name

Return values
mixed

setPath()

Set the path of the cookie

public setPath(string $path) : mixed
Parameters
$path : string

Path of the cookie

Return values
mixed

setSecure()

Set whether or not the cookie is secure

public setSecure(bool $secure) : mixed
Parameters
$secure : bool

Set to true or false if secure

Return values
mixed

setValue()

Set the cookie value

public setValue(string $value) : mixed
Parameters
$value : string

Cookie value

Return values
mixed

toArray()

public toArray() : mixed
Return values
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

Search results