Overview

Packages

  • Requests
    • Authentication
    • Cookies
    • Proxy
    • Session
    • Transport
    • Utilities

Classes

  • Requests_Cookie
  • Requests_Cookie_Jar
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated

Warning! You are currently reading the documentation for Requests 1.x.

It is recommended to upgrade to Requests 2.x at your earliest convenience. Upgrading to Requests 2.x is fairly straight-forward.
A full list of the changes can be found in the Changelog.

Visit the documentation for Requests_Cookie in Requests 2.x.

Class Requests_Cookie

Cookie storage object

Package: Requests\Cookies
Located at Requests/Cookie.php
Methods summary
public
# __construct( string $name, string $value, array|Requests_Utility_CaseInsensitiveDictionary $attributes = array(), $flags = array(), $reference_time = null )

Create a new cookie object

Create a new cookie object

Parameters

$name
$value
$attributes
Associative array of attribute data
$flags
$reference_time
public boolean
# is_expired( )

Check if a cookie is expired.

Check if a cookie is expired.

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

Returns

boolean
True if expired, false if time is valid.
public boolean
# uri_matches( Requests_IRI $uri )

Check if a cookie is valid for a given URI

Check if a cookie is valid for a given URI

Parameters

$uri
URI to check

Returns

boolean
Whether the cookie is valid for the given URI
public boolean
# domain_matches( string $string )

Check if a cookie is valid for a given domain

Check if a cookie is valid for a given domain

Parameters

$string
Domain to check

Returns

boolean
Whether the cookie is valid for the given domain
public boolean
# path_matches( string $request_path )

Check if a cookie is valid for a given path

Check if a cookie is valid for a given path

From the path-match check in RFC 6265 section 5.1.4

Parameters

$request_path
Path to check

Returns

boolean
Whether the cookie is valid for the given path
public boolean
# normalize( )

Normalize cookie and attributes

Normalize cookie and attributes

Returns

boolean
Whether the cookie was successfully normalized
protected mixed
# normalize_attribute( string $name, string|boolean $value )

Parse an individual cookie attribute

Parse an individual cookie attribute

Handles parsing individual attributes from the cookie values.

Parameters

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

Returns

mixed
Value if available, or null if the attribute value is invalid (and should be skipped)
public string
# format_for_header( )

Format a cookie for a Cookie header

Format a cookie for a Cookie header

This is used when sending cookies to a server.

Returns

string
Cookie formatted for Cookie header
public string
# formatForHeader( )

Format a cookie for a Cookie header

Format a cookie for a Cookie header

Deprecated

Use Requests_Cookie::format_for_header()

Returns

string

Codecoverageignore

public string
# format_for_set_cookie( )

Format a cookie for a Set-Cookie header

Format a cookie for a Set-Cookie header

This is used when sending cookies to clients. This isn't really applicable to client-side usage, but might be handy for debugging.

Returns

string
Cookie formatted for Set-Cookie header
public string
# formatForSetCookie( )

Format a cookie for a Set-Cookie header

Format a cookie for a Set-Cookie header

Deprecated

Use Requests_Cookie::format_for_set_cookie()

Returns

string

Codecoverageignore

public
# __toString( )

Get the cookie value

Get the cookie value

Attributes and other data can be accessed via methods.

public static Requests_Cookie
# parse( string $string, $name = '', $reference_time = null )

Parse a cookie string into a cookie object

Parse a cookie string into a cookie object

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
header value (from a Set-Cookie header)
$name
$reference_time

Returns

Requests_Cookie
Parsed cookie object
public static array
# parse_from_headers( Requests_Response_Headers $headers, Requests_IRI $origin = null, integer|null $time = null )

Parse all Set-Cookie headers from request headers

Parse all Set-Cookie headers from request headers

Parameters

$headers
Headers to parse from
$origin
URI for comparing cookie origins
$time
Reference time for expiration calculation

Returns

array
public static array
# parseFromHeaders( Requests_Response_Headers $headers )

Parse all Set-Cookie headers from request headers

Parse all Set-Cookie headers from request headers

Deprecated

Use Requests_Cookie::parse_from_headers()

Returns

array

Codecoverageignore

Properties summary
public string $name

Cookie name.

Cookie name.

#
public string $value

Cookie value.

Cookie value.

#
public Requests_Utility_CaseInsensitiveDictionary|array $attributes

Cookie attributes

Cookie attributes

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

# array()
public array $flags

Cookie flags

Cookie flags

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

# array()
public integer $reference_time

Reference time for relative calculations

Reference time for relative calculations

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

# 0
Requests 1.8.1 API Documentation API documentation generated by ApiGen