Cookie storage object

package Requests
subpackage Cookies

 Methods

Create a new cookie object

__construct(string $name, string $value, array|\Requests_Utility_CaseInsensitiveDictionary $attributes = array(), $flags = array(), $reference_time = null

Parameters

$name

string

$value

string

$attributes

array\Requests_Utility_CaseInsensitiveDictionary

Associative array of attribute data

$flags

$reference_time

Get the cookie value

__toString() 

Attributes and other data can be accessed via methods.

Check if a cookie is valid for a given domain

domain_matches(string $string) : boolean

Parameters

$string

string

Domain to check

Returns

booleanWhether the cookie is valid for the given domain

Format a cookie for a Cookie header

formatForHeader() : string
codeCoverageIgnore
deprecated Use {@see Requests_Cookie::format_for_header}

Returns

string

Format a cookie for a Set-Cookie header

formatForSetCookie() : string
codeCoverageIgnore
deprecated Use {@see Requests_Cookie::format_for_set_cookie}

Returns

string

Format a cookie for a Cookie header

format_for_header() : string

This is used when sending cookies to a server.

Returns

stringCookie formatted for Cookie header

Check if a cookie is expired.

is_expired() : boolean

Checks the age against $this->reference_time to determine if the cookie is expired.

Returns

booleanTrue if expired, false if time is valid.

Normalize cookie and attributes

normalize() : boolean

Returns

booleanWhether the cookie was successfully normalized

Parse a cookie string into a cookie object

parse(string $string, $name = '', $reference_time = null) : \Requests_Cookie
Static

Based on Mozilla's parsing code in Firefox and related projects, which is an intentional deviation from RFC 2109 and RFC 2616. RFC 6265 specifies some of this handling, but not in a thorough manner.

Parameters

$string

string

Cookie header value (from a Set-Cookie header)

$name

$reference_time

Returns

\Requests_CookieParsed cookie object

Parse all Set-Cookie headers from request headers

parseFromHeaders(\Requests_Response_Headers $headers) : string
Static
codeCoverageIgnore
deprecated Use {@see Requests_Cookie::parse_from_headers}

Parameters

$headers

Returns

string

Parse all Set-Cookie headers from request headers

parse_from_headers(\Requests_Response_Headers $headers, \Requests_IRI|null $origin = null, integer|null $time = null) : array
Static

Parameters

$headers

\Requests_Response_Headers

Headers to parse from

$origin

\Requests_IRInull

URI for comparing cookie origins

$time

integernull

Reference time for expiration calculation

Returns

array

Check if a cookie is valid for a given path

path_matches(string $request_path) : boolean

From the path-match check in RFC 6265 section 5.1.4

Parameters

$request_path

string

Path to check

Returns

booleanWhether the cookie is valid for the given path

Check if a cookie is valid for a given URI

uri_matches(\Requests_IRI $uri) : boolean

Parameters

$uri

\Requests_IRI

URI to check

Returns

booleanWhether the cookie is valid for the given URI

Parse an individual cookie attribute

normalize_attribute(string $name, string|boolean $value) : mixed

Handles parsing individual attributes from the cookie values.

Parameters

$name

string

Attribute name

$value

stringboolean

Attribute value (string value, or true if empty/flag)

Returns

mixedValue if available, or null if the attribute value is invalid (and should be skipped)

 Properties

 

Cookie attributes

$attributes : \Requests_Utility_CaseInsensitiveDictionary | array

Default

array()

Valid keys are (currently) path, domain, expires, max-age, secure and httponly.

 

Cookie flags

$flags : array

Default

array()

Valid keys are (currently) creation, last-access, persistent and host-only.

 

Cookie name.

$name : string

Default

 

Reference time for relative calculations

$reference_time : integer

Default

0

This is used in place of time() when calculating Max-Age expiration and checking time validity.

 

Cookie value.

$value : string

Default