HTTP_Request2
[ class tree: HTTP_Request2 ] [ index: HTTP_Request2 ] [ all elements ]

Class: HTTP_Request2_CookieJar

Source Location: /HTTP_Request2-2.2.1/HTTP/Request2/CookieJar.php

Class Overview


Stores cookies and passes them between HTTP requests


Author(s):

Version:

  • Release: @package_version@

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 34]
Stores cookies and passes them between HTTP requests


[ Top ]


Class Variables

$cookies = array()

[line 50]

Array of stored cookies

The array is indexed by domain, path and cookie name .example.com / some_cookie => cookie data /subdir other_cookie => cookie data .example.org ...

  • Access: protected

Type:   array


[ Top ]

$psl = array()

[line 69]

Array with Public Suffix List data

Type:   array


[ Top ]

$serializeSession =  false

[line 56]

Whether session cookies should be serialized when serializing the jar
  • Access: protected

Type:   bool


[ Top ]

$useList =  true

[line 62]

Whether Public Suffix List should be used for domain matching
  • Access: protected

Type:   bool


[ Top ]



Method Detail

__construct (Constructor)   [line 79]

HTTP_Request2_CookieJar __construct( [bool $serializeSessionCookies = false], [bool $usePublicSuffixList = true])

Class constructor, sets various options
  • Access: public

Parameters:

bool   $serializeSessionCookies     Controls serializing session cookies, see serializeSessionCookies()
bool   $usePublicSuffixList     Controls using Public Suffix List, see usePublicSuffixList()

[ Top ]

addCookiesFromResponse   [line 226]

void addCookiesFromResponse( HTTP_Request2_Response $response, $setter)

Adds cookies set in HTTP response to the jar
  • Access: public

Parameters:

HTTP_Request2_Response   $response     HTTP response message
Net_URL2   $setter     original request URL, needed for setting default domain/path

[ Top ]

checkAndUpdateFields   [line 122]

array checkAndUpdateFields( $cookie, [ $setter = null])

Checks cookie array for correctness, possibly updating its 'domain', 'path' and 'expires' fields

The checks are as follows:

  • cookie array should contain 'name' and 'value' fields;
  • name and value should not contain disallowed symbols;
  • 'expires' should be either empty parseable by DateTime;
  • 'domain' and 'path' should be either not empty or an URL where cookie was set should be provided.
  • if $setter is provided, then document at that URL should be allowed to set a cookie for that 'domain'. If $setter is not provided, then no domain checks will be made.
'expires' field will be converted to ISO8601 format from COOKIE format, 'domain' and 'path' will be set from setter URL if empty.

  • Return: Updated cookie array
  • Throws: HTTP_Request2_MessageException
  • Throws: HTTP_Request2_LogicException
  • Access: protected

Parameters:

array   $cookie     cookie data, as returned by HTTP_Request2_Response::getCookies()
Net_URL2   $setter     URL of the document that sent Set-Cookie header

[ Top ]

checkDomainsList   [line 471]

string|null checkDomainsList( $domainParts, mixed $listNode)

Recursive helper method for getRegisteredDomain()
  • Return: concatenated domain parts, null in case of error
  • Access: protected

Parameters:

array   $domainParts     remaining domain parts
mixed   $listNode     node in HTTP_Request2_CookieJar::$psl to check

[ Top ]

domainMatch   [line 398]

bool domainMatch( string $requestHost, string $cookieDomain)

Checks whether a cookie domain matches a request host.

The method is used by store() to check for whether a document at given URL can set a cookie with a given domain attribute and by getMatching() to find cookies matching the request URL.

  • Return: match success
  • Access: public

Parameters:

string   $requestHost     request host
string   $cookieDomain     cookie domain

[ Top ]

getAll   [line 286]

array getAll( )

Returns all cookies stored in a jar
  • Access: public

[ Top ]

getMatching   [line 246]

array|string getMatching( $url, [bool $asString = false])

Returns all cookies matching a given request URL

The following checks are made:

  • cookie domain should match request host
  • cookie path should be a prefix for request path
  • 'secure' cookies will only be sent for HTTPS requests

  • Return: Matching cookies
  • Access: public

Parameters:

Net_URL2   $url     Request url
bool   $asString     Whether to return cookies as string for "Cookie: " header

[ Top ]

getRegisteredDomain   [line 431]

string|bool getRegisteredDomain( string $domain)

Removes subdomains to get the registered domain (the first after top-level)

The method will check Public Suffix List to find out where top-level domain ends and registered domain starts. It will remove domain parts to the left of registered one.

  • Return: registered domain, will return false if $domain is either invalid or a TLD itself
  • Access: public

Parameters:

string   $domain     domain name

[ Top ]

now   [line 91]

string now( )

Returns current time formatted in ISO-8601 at UTC timezone
  • Access: protected

[ Top ]

serialize   [line 342]

string serialize( )

Returns string representation of object
  • See: Serializable::serialize()
  • Access: public

[ Top ]

serializeSessionCookies   [line 304]

void serializeSessionCookies( boolean $serialize)

Sets whether session cookies should be serialized when serializing the jar
  • Access: public

Parameters:

boolean   $serialize     serialize?

[ Top ]

store   [line 199]

void store( $cookie, [ $setter = null])

Stores a cookie in the jar
  • Throws: HTTP_Request2_Exception
  • Access: public

Parameters:

array   $cookie     cookie data, as returned by HTTP_Request2_Response::getCookies()
Net_URL2   $setter     URL of the document that sent Set-Cookie header

[ Top ]

unserialize   [line 366]

void unserialize( string $serialized)

Constructs the object from serialized string
  • See: Serializable::unserialize()
  • Access: public

Parameters:

string   $serialized     string representation

[ Top ]

usePublicSuffixList   [line 330]

void usePublicSuffixList( boolean $useList)

Sets whether Public Suffix List should be used for restricting cookie-setting

Without PSL domainMatch() will only prevent setting cookies for top-level domains like '.com' or '.org'. However, it will not prevent setting a cookie for '.co.uk' even though only third-level registrations are possible in .uk domain.

With the List it is possible to find the highest level at which a domain may be registered for a particular top-level domain and consequently prevent cookies set for '.co.uk' or '.msk.ru'. The same list is used by Firefox, Chrome and Opera browsers to restrict cookie setting.

Note that PSL is licensed differently to HTTP_Request2 package (refer to the license information in public-suffix-list.php), so you can disable its use if this is an issue for you.


Parameters:

boolean   $useList     use the list?

[ Top ]


Documentation generated on Thu, 16 Jan 2014 20:00:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.