Documentation

Cookie
in package
implements ToArrayInterface

Set-Cookie object

Table of Contents

Interfaces

ToArrayInterface
An object that can be represented as an array

Properties

$data  : array<string|int, mixed>
$invalidCharString  : string

Methods

__construct()  : mixed
getAttribute()  : null|string
Get a specific data point from the extra cookie data
getAttributes()  : array<string|int, mixed>
Get an array of extra cookie data
getComment()  : string|null
Get the comment
getCommentUrl()  : string|null
Get the comment URL of the cookie
getDiscard()  : null|bool
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
getPorts()  : array<string|int, mixed>
Get an array of acceptable ports this cookie can be used with
getSecure()  : null|bool
Get whether or not this is a secure cookie
getValue()  : string
Get the cookie value
getVersion()  : mixed
Version of the cookie specification. RFC 2965 is 1
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
matchesPort()  : bool
Check if the cookie is compatible with a specific port
setAttribute()  : Cookie
Set a cookie data attribute
setComment()  : Cookie
Set the comment of the cookie
setCommentUrl()  : Cookie
Set the comment URL of the cookie
setDiscard()  : Cookie
Set whether or not this is a session cookie
setDomain()  : Cookie
Set the domain of the cookie
setExpires()  : Cookie
Set the unix timestamp for which the cookie will expire
setHttpOnly()  : Cookie
Set whether or not this is an HTTP only cookie
setMaxAge()  : Cookie
Set the max-age of the cookie
setName()  : Cookie
Set the cookie name
setPath()  : Cookie
Set the path of the cookie
setPorts()  : Cookie
Set a list of acceptable ports this cookie can be used with
setSecure()  : Cookie
Set whether or not the cookie is secure
setValue()  : Cookie
Set the cookie value
setVersion()  : Cookie
Set the cookie version
toArray()  : array<string|int, mixed>
Get the cookie as an array
validate()  : bool|string
Check if the cookie is valid according to RFC 6265
getInvalidCharacters()  : array<string|int, mixed>
Gets an array of invalid cookie characters
setData()  : Cookie
Set a value and return the cookie object

Properties

$data

protected array<string|int, mixed> $data

Cookie data

$invalidCharString

protected static string $invalidCharString

ASCII codes not valid for for use in a cookie name

Cookie names are defined as 'token', according to RFC 2616, Section 2.2 A valid token may contain any CHAR except CTLs (ASCII 0 - 31 or 127) or any of the following separators

Methods

__construct()

public __construct([array<string|int, mixed> $data = array() ]) : mixed
Parameters
$data : array<string|int, mixed> = array()

Array of cookie data provided by a Cookie parser

getAttribute()

Get a specific data point from the extra cookie data

public getAttribute(string $name) : null|string
Parameters
$name : string

Name of the data point to retrieve

Return values
null|string

getAttributes()

Get an array of extra cookie data

public getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getComment()

Get the comment

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

getCommentUrl()

Get the comment URL of the cookie

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

getDiscard()

Get whether or not this is a session cookie

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

getDomain()

Get the domain

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

getExpires()

The UNIX timestamp when the cookie expires

public getExpires() : 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

getPorts()

Get an array of acceptable ports this cookie can be used with

public getPorts() : array<string|int, mixed>
Return values
array<string|int, mixed>

getSecure()

Get whether or not this is a secure cookie

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

getValue()

Get the cookie value

public getValue() : string
Return values
string

getVersion()

Version of the cookie specification. RFC 2965 is 1

public getVersion() : mixed

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 $path) : bool
Parameters
$path : string

Path to check against

Return values
bool

matchesPort()

Check if the cookie is compatible with a specific port

public matchesPort(int $port) : bool
Parameters
$port : int

Port to check

Return values
bool

setAttribute()

Set a cookie data attribute

public setAttribute(string $name, string $value) : Cookie
Parameters
$name : string

Name of the attribute to set

$value : string

Value to set

Return values
Cookie

setComment()

Set the comment of the cookie

public setComment(string $comment) : Cookie
Parameters
$comment : string

Cookie comment

Return values
Cookie

setCommentUrl()

Set the comment URL of the cookie

public setCommentUrl(string $commentUrl) : Cookie
Parameters
$commentUrl : string

Cookie comment URL for more information

Return values
Cookie

setDiscard()

Set whether or not this is a session cookie

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

Set to true or false if this is a session cookie

Return values
Cookie

setDomain()

Set the domain of the cookie

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

setExpires()

Set the unix timestamp for which the cookie will expire

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

Unix timestamp

Return values
Cookie

setHttpOnly()

Set whether or not this is an HTTP only cookie

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

Set to true or false if this is HTTP only

Return values
Cookie

setMaxAge()

Set the max-age of the cookie

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

Max age of the cookie in seconds

Return values
Cookie

setName()

Set the cookie name

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

Cookie name

Return values
Cookie

setPath()

Set the path of the cookie

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

Path of the cookie

Return values
Cookie

setPorts()

Set a list of acceptable ports this cookie can be used with

public setPorts(array<string|int, mixed> $ports) : Cookie
Parameters
$ports : array<string|int, mixed>

Array of acceptable ports

Return values
Cookie

setSecure()

Set whether or not the cookie is secure

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

Set to true or false if secure

Return values
Cookie

setValue()

Set the cookie value

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

Cookie value

Return values
Cookie

setVersion()

Set the cookie version

public setVersion(string|int $version) : Cookie
Parameters
$version : string|int

Version to set

Return values
Cookie

toArray()

Get the cookie as an array

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

getInvalidCharacters()

Gets an array of invalid cookie characters

protected static getInvalidCharacters() : array<string|int, mixed>
Return values
array<string|int, mixed>

setData()

Set a value and return the cookie object

private setData(string $key, string $value) : Cookie
Parameters
$key : string

Key to set

$value : string

Value to set

Return values
Cookie

        
On this page

Search results