Documentation

Cookie
in package

Cookie represents an HTTP cookie.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Constants

DATE_FORMATS  = ['D, d M Y H:i:s T', 'D, d-M-y H:i:s T', 'D, d-M-Y H:i:s T', 'D, d-m-y H:i:s T', 'D, d-m-Y H:i:s T', 'D M j G:i:s Y', 'D M d H:i:s Y T']
Handles dates as defined by RFC 2616 section 3.3.1, and also some other non-standard, but common formats.

Properties

$domain  : mixed
$expires  : mixed
$httponly  : mixed
$name  : mixed
$path  : mixed
$rawValue  : mixed
$secure  : mixed
$value  : mixed
$samesite  : string|null

Methods

__construct()  : mixed
Sets a cookie.
__toString()  : string
Returns the HTTP representation of the Cookie.
fromString()  : static
Creates a Cookie instance from a Set-Cookie header value.
getDomain()  : string
Gets the domain of the cookie.
getExpiresTime()  : string|null
Gets the expires time of the cookie.
getName()  : string
Gets the name of the cookie.
getPath()  : string
Gets the path of the cookie.
getRawValue()  : string
Gets the raw value of the cookie.
getSameSite()  : string|null
Gets the samesite attribute of the cookie.
getValue()  : string
Gets the value of the cookie.
isExpired()  : bool
Returns true if the cookie has expired.
isHttpOnly()  : bool
Returns the httponly flag of the cookie.
isSecure()  : bool
Returns the secure flag of the cookie.
parseDate()  : string|null

Constants

DATE_FORMATS

Handles dates as defined by RFC 2616 section 3.3.1, and also some other non-standard, but common formats.

private mixed DATE_FORMATS = ['D, d M Y H:i:s T', 'D, d-M-y H:i:s T', 'D, d-M-Y H:i:s T', 'D, d-m-y H:i:s T', 'D, d-m-Y H:i:s T', 'D M j G:i:s Y', 'D M d H:i:s Y T']

Properties

$expires

protected mixed $expires

$httponly

protected mixed $httponly

$rawValue

protected mixed $rawValue

$samesite

private string|null $samesite

Methods

__construct()

Sets a cookie.

public __construct(string $name, string|null $value[, string|null $expires = null ][, string|null $path = null ][, string $domain = '' ][, bool $secure = false ][, bool $httponly = true ][, bool $encodedValue = false ][, string|null $samesite = null ]) : mixed
Parameters
$name : string

The cookie name

$value : string|null

The value of the cookie

$expires : string|null = null

The time the cookie expires

$path : string|null = null

The path on the server in which the cookie will be available on

$domain : string = ''

The domain that the cookie is available

$secure : bool = false

Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client

$httponly : bool = true

The cookie httponly flag

$encodedValue : bool = false

Whether the value is encoded or not

$samesite : string|null = null

The cookie samesite attribute

__toString()

Returns the HTTP representation of the Cookie.

public __toString() : string
Return values
string

fromString()

Creates a Cookie instance from a Set-Cookie header value.

public static fromString(string $cookie[, string $url = null ]) : static
Parameters
$cookie : string
$url : string = null
Tags
throws
InvalidArgumentException
Return values
static

getDomain()

Gets the domain of the cookie.

public getDomain() : string
Return values
string

getExpiresTime()

Gets the expires time of the cookie.

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

getName()

Gets the name of the cookie.

public getName() : string
Return values
string

getPath()

Gets the path of the cookie.

public getPath() : string
Return values
string

getRawValue()

Gets the raw value of the cookie.

public getRawValue() : string
Return values
string

getSameSite()

Gets the samesite attribute of the cookie.

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

getValue()

Gets the value of the cookie.

public getValue() : string
Return values
string

isExpired()

Returns true if the cookie has expired.

public isExpired() : bool
Return values
bool

isHttpOnly()

Returns the httponly flag of the cookie.

public isHttpOnly() : bool
Return values
bool

isSecure()

Returns the secure flag of the cookie.

public isSecure() : bool
Return values
bool

parseDate()

private static parseDate(string $dateValue) : string|null
Parameters
$dateValue : string
Return values
string|null

        
On this page

Search results