Set-Cookie object
- Full name:
\GuzzleHttp\Cookie\SetCookie
private static array $defaults
- This property is static.
private array $data
Create a new SetCookie object from a string.
public static fromString(string $cookie): self
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$cookie |
string | Set-Cookie header string |
public __construct(array $data = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$data |
array | Array of cookie data provided by a Cookie parser |
public __toString(): mixed
public toArray(): array
Get the cookie name.
public getName(): string
Set the cookie name.
public setName(string $name): void
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string | Cookie name |
Get the cookie value.
public getValue(): string|null
Set the cookie value.
public setValue(string $value): void
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
string | Cookie value |
Get the domain.
public getDomain(): string|null
Set the domain of the cookie.
public setDomain(string|null $domain): void
Parameters:
Parameter | Type | Description |
---|---|---|
$domain |
string|null |
Get the path.
public getPath(): string
Set the path of the cookie.
public setPath(string $path): void
Parameters:
Parameter | Type | Description |
---|---|---|
$path |
string | Path of the cookie |
Maximum lifetime of the cookie in seconds.
public getMaxAge(): int|null
Set the max-age of the cookie.
public setMaxAge(int|null $maxAge): void
Parameters:
Parameter | Type | Description |
---|---|---|
$maxAge |
int|null | Max age of the cookie in seconds |
The UNIX timestamp when the cookie Expires.
public getExpires(): string|int|null
Set the unix timestamp for which the cookie will expire.
public setExpires(int|string|null $timestamp): void
Parameters:
Parameter | Type | Description |
---|---|---|
$timestamp |
int|string|null | Unix timestamp or any English textual datetime description. |
Get whether or not this is a secure cookie.
public getSecure(): bool
Set whether or not the cookie is secure.
public setSecure(bool $secure): void
Parameters:
Parameter | Type | Description |
---|---|---|
$secure |
bool | Set to true or false if secure |
Get whether or not this is a session cookie.
public getDiscard(): bool|null
Set whether or not this is a session cookie.
public setDiscard(bool $discard): void
Parameters:
Parameter | Type | Description |
---|---|---|
$discard |
bool | Set to true or false if this is a session cookie |
Get whether or not this is an HTTP only cookie.
public getHttpOnly(): bool
Set whether or not this is an HTTP only cookie.
public setHttpOnly(bool $httpOnly): void
Parameters:
Parameter | Type | Description |
---|---|---|
$httpOnly |
bool | Set to true or false if this is HTTP only |
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:
Parameter | Type | Description |
---|---|---|
$requestPath |
string | Path to check against |
Check if the cookie matches a domain value.
public matchesDomain(string $domain): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$domain |
string | Domain to check against |
Check if the cookie is expired.
public isExpired(): bool
Check if the cookie is valid according to RFC 6265.
public validate(): bool|string
Return Value:
Returns true if valid or an error message if invalid