HumHub Documentation (unofficial)

SetCookie
in package
implements MultipleHeaderInterface

Tags
see
http://www.ietf.org/rfc/rfc2109.txt
see
http://www.w3.org/Protocols/rfc2109/rfc2109
throws
InvalidArgumentException

Table of Contents

Interfaces

MultipleHeaderInterface
Interface for HTTP Header classes.

Constants

SAME_SITE_LAX  = 'Lax'
Cookie will not be passed for any cross-domain requests unless it's a regular link that navigates user to the target site.
SAME_SITE_NONE  = 'None'
Cookie will be sent with same-site and cross-site requests.
SAME_SITE_STRICT  = 'Strict'
Cookie will not be sent for any cross-domain requests whatsoever.

Properties

$type  : string
$domain  : string|null
Cookie domain
$encodeValue  : bool
$expires  : int|null
Cookie expiry date
$httponly  : bool|null
$maxAge  : int|null
Max Age
$name  : string|null
Cookie name
$path  : string|null
Cookie path
$quoteFieldValue  : bool
If the value need to be quoted or not
$sameSite  : string|null
$secure  : bool|null
Whether the cookie is secure or not
$value  : string|null
Cookie value
$version  : int|null
Version

Methods

__construct()  : mixed
Cookie object constructor
fromString()  : array<string|int, mixed>|SetCookie
Factory to generate a header object from a string
getDomain()  : string|null
getEncodeValue()  : bool
getExpires()  : int|string|null
getFieldName()  : string
Retrieve header name
getFieldValue()  : string
Retrieve header value
getMaxAge()  : int|null
getName()  : string|null
getPath()  : string|null
getSameSite()  : string|null
getValue()  : string|null
getVersion()  : int|null
hasQuoteFieldValue()  : bool
Check whether the value for this cookie should be quoted
isExpired()  : bool
Check whether the cookie has expired
isHttponly()  : bool|null
isSecure()  : bool|null
isSessionCookie()  : bool
Check whether the cookie is a session cookie (has no expiry time set)
isValidForRequest()  : bool
match()  : bool
Checks whether the cookie should be sent or not in a specific scenario
matchCookieDomain()  : bool
Check if a cookie's domain matches a host name.
matchCookiePath()  : bool
Check if a cookie's path matches a URL path
setDomain()  : $this
setEncodeValue()  : mixed
setExpires()  : $this
setHttponly()  : $this
setMaxAge()  : $this
setName()  : $this
setPath()  : $this
setQuoteFieldValue()  : $this
Set whether the value for this cookie should be quoted
setSameSite()  : $this
setSecure()  : $this
setValue()  : $this
setVersion()  : $this
toString()  : string
Cast to string
toStringMultipleHeaders()  : string

Constants

SAME_SITE_LAX

Cookie will not be passed for any cross-domain requests unless it's a regular link that navigates user to the target site.

public mixed SAME_SITE_LAX = 'Lax'

Other requests methods (such as POST and PUT) and XHR requests will not contain this cookie.

SAME_SITE_NONE

Cookie will be sent with same-site and cross-site requests.

public mixed SAME_SITE_NONE = 'None'

SAME_SITE_STRICT

Cookie will not be sent for any cross-domain requests whatsoever.

public mixed SAME_SITE_STRICT = 'Strict'

Even if the user simply navigates to the target site with a regular link, the cookie will not be sent.

Properties

$type

public string $type
Tags
deprecated

This property is deprecated, and will be removed

$domain

Cookie domain

protected string|null $domain

$encodeValue

protected bool $encodeValue = true

$expires

Cookie expiry date

protected int|null $expires

$name

Cookie name

protected string|null $name

$path

Cookie path

protected string|null $path

$quoteFieldValue

If the value need to be quoted or not

protected bool $quoteFieldValue = false

$secure

Whether the cookie is secure or not

protected bool|null $secure

$value

Cookie value

protected string|null $value

$version

Version

protected int|null $version

Methods

__construct()

Cookie object constructor

public __construct([string|null $name = null ][, string|null $value = null ][, int|string|DateTime|null $expires = null ][, string|null $path = null ][, string|null $domain = null ][, bool $secure = false ][, bool $httponly = false ][, int|null $maxAge = null ][, int|null $version = null ][, string|null $sameSite = null ]) : mixed
Parameters
$name : string|null = null
$value : string|null = null
$expires : int|string|DateTime|null = null
$path : string|null = null
$domain : string|null = null
$secure : bool = false
$httponly : bool = false
$maxAge : int|null = null
$version : int|null = null
$sameSite : string|null = null
Tags
todo

Add validation of each one of the parameters (legal domain, etc.)

fromString()

Factory to generate a header object from a string

public static fromString(string $headerLine[, bool $bypassHeaderFieldName = false ]) : array<string|int, mixed>|SetCookie
Parameters
$headerLine : string
$bypassHeaderFieldName : bool = false
Tags
static
throws
InvalidArgumentException
Return values
array<string|int, mixed>|SetCookie

getDomain()

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

getEncodeValue()

public getEncodeValue() : bool
Return values
bool

getExpires()

public getExpires([bool $inSeconds = false ]) : int|string|null
Parameters
$inSeconds : bool = false
Return values
int|string|null

getFieldName()

Retrieve header name

public getFieldName() : string
Return values
string

'Set-Cookie'

getMaxAge()

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

getName()

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

getPath()

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

getSameSite()

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

getValue()

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

getVersion()

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

hasQuoteFieldValue()

Check whether the value for this cookie should be quoted

public hasQuoteFieldValue() : bool
Return values
bool

isExpired()

Check whether the cookie has expired

public isExpired([int|null $now = null ]) : bool

Always returns false if the cookie is a session cookie (has no expiry time)

Parameters
$now : int|null = null

Timestamp to consider as "now"

Return values
bool

isHttponly()

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

isSecure()

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

isSessionCookie()

Check whether the cookie is a session cookie (has no expiry time set)

public isSessionCookie() : bool
Return values
bool

isValidForRequest()

public isValidForRequest(string $requestDomain, string $path[, bool $isSecure = false ]) : bool
Parameters
$requestDomain : string
$path : string
$isSecure : bool = false
Return values
bool

match()

Checks whether the cookie should be sent or not in a specific scenario

public match(string|Uri $uri[, bool $matchSessionCookies = true ][, int|null $now = null ]) : bool
Parameters
$uri : string|Uri

URI to check against (secure, domain, path)

$matchSessionCookies : bool = true

Whether to send session cookies

$now : int|null = null

Override the current time when checking for expiry time

Tags
throws
InvalidArgumentException

If URI does not have HTTP or HTTPS scheme.

Return values
bool

matchCookieDomain()

Check if a cookie's domain matches a host name.

public static matchCookieDomain(string $cookieDomain, string $host) : bool

Used by Laminas\Http\Cookies for cookie matching

Parameters
$cookieDomain : string
$host : string
Return values
bool

matchCookiePath()

Check if a cookie's path matches a URL path

public static matchCookiePath(string $cookiePath, string $path) : bool

Used by Laminas\Http\Cookies for cookie matching

Parameters
$cookiePath : string
$path : string
Return values
bool

setDomain()

public setDomain(string|null $domain) : $this
Parameters
$domain : string|null
Return values
$this

setEncodeValue()

public setEncodeValue(bool $encodeValue) : mixed
Parameters
$encodeValue : bool

setExpires()

public setExpires(int|string|DateTime|null $expires) : $this
Parameters
$expires : int|string|DateTime|null
Tags
throws
InvalidArgumentException
Return values
$this

setHttponly()

public setHttponly(bool|null $httponly) : $this
Parameters
$httponly : bool|null
Return values
$this

setMaxAge()

public setMaxAge(int $maxAge) : $this
Parameters
$maxAge : int
Return values
$this

setPath()

public setPath(string|null $path) : $this
Parameters
$path : string|null
Return values
$this

setQuoteFieldValue()

Set whether the value for this cookie should be quoted

public setQuoteFieldValue(bool $quotedValue) : $this
Parameters
$quotedValue : bool
Return values
$this

setSecure()

public setSecure(bool|null $secure) : $this
Parameters
$secure : bool|null
Return values
$this

setValue()

public setValue(string|null $value) : $this
Parameters
$value : string|null
Return values
$this

toString()

Cast to string

public toString() : string
Return values
string

toStringMultipleHeaders()

public toStringMultipleHeaders(array<string|int, mixed> $headers) : string
Parameters
$headers : array<string|int, mixed>
Tags
throws
RuntimeException
Return values
string

        
On this page

Search results