SetCookie
in package
implements
MultipleHeaderInterface
Tags
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
$domain
Cookie domain
protected
string|null
$domain
$encodeValue
protected
bool
$encodeValue
= true
$expires
Cookie expiry date
protected
int|null
$expires
$httponly
protected
bool|null
$httponly
$maxAge
Max Age
protected
int|null
$maxAge
$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
$sameSite
protected
string|null
$sameSite
$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
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
Return values
array<string|int, mixed>|SetCookiegetDomain()
public
getDomain() : string|null
Return values
string|nullgetEncodeValue()
public
getEncodeValue() : bool
Return values
boolgetExpires()
public
getExpires([bool $inSeconds = false ]) : int|string|null
Parameters
- $inSeconds : bool = false
Return values
int|string|nullgetFieldName()
Retrieve header name
public
getFieldName() : string
Return values
string —'Set-Cookie'
getFieldValue()
Retrieve header value
public
getFieldValue() : string
Tags
Return values
stringgetMaxAge()
public
getMaxAge() : int|null
Return values
int|nullgetName()
public
getName() : string|null
Return values
string|nullgetPath()
public
getPath() : string|null
Return values
string|nullgetSameSite()
public
getSameSite() : string|null
Return values
string|nullgetValue()
public
getValue() : string|null
Return values
string|nullgetVersion()
public
getVersion() : int|null
Return values
int|nullhasQuoteFieldValue()
Check whether the value for this cookie should be quoted
public
hasQuoteFieldValue() : bool
Return values
boolisExpired()
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
boolisHttponly()
public
isHttponly() : bool|null
Return values
bool|nullisSecure()
public
isSecure() : bool|null
Return values
bool|nullisSessionCookie()
Check whether the cookie is a session cookie (has no expiry time set)
public
isSessionCookie() : bool
Return values
boolisValidForRequest()
public
isValidForRequest(string $requestDomain, string $path[, bool $isSecure = false ]) : bool
Parameters
- $requestDomain : string
- $path : string
- $isSecure : bool = false
Return values
boolmatch()
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
Return values
boolmatchCookieDomain()
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
boolmatchCookiePath()
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
boolsetDomain()
public
setDomain(string|null $domain) : $this
Parameters
- $domain : string|null
Return values
$thissetEncodeValue()
public
setEncodeValue(bool $encodeValue) : mixed
Parameters
- $encodeValue : bool
setExpires()
public
setExpires(int|string|DateTime|null $expires) : $this
Parameters
- $expires : int|string|DateTime|null
Tags
Return values
$thissetHttponly()
public
setHttponly(bool|null $httponly) : $this
Parameters
- $httponly : bool|null
Return values
$thissetMaxAge()
public
setMaxAge(int $maxAge) : $this
Parameters
- $maxAge : int
Return values
$thissetName()
public
setName(string|null $name) : $this
Parameters
- $name : string|null
Tags
Return values
$thissetPath()
public
setPath(string|null $path) : $this
Parameters
- $path : string|null
Return values
$thissetQuoteFieldValue()
Set whether the value for this cookie should be quoted
public
setQuoteFieldValue(bool $quotedValue) : $this
Parameters
- $quotedValue : bool
Return values
$thissetSameSite()
public
setSameSite(string|null $sameSite) : $this
Parameters
- $sameSite : string|null
Tags
Return values
$thissetSecure()
public
setSecure(bool|null $secure) : $this
Parameters
- $secure : bool|null
Return values
$thissetValue()
public
setValue(string|null $value) : $this
Parameters
- $value : string|null
Return values
$thissetVersion()
public
setVersion(int|null $version) : $this
Parameters
- $version : int|null
Tags
Return values
$thistoString()
Cast to string
public
toString() : string
Return values
stringtoStringMultipleHeaders()
public
toStringMultipleHeaders(array<string|int, mixed> $headers) : string
Parameters
- $headers : array<string|int, mixed>