A Zend_Http_CookieJar object is designed to contain and maintain HTTP cookies, and should be used along with Zend_Http_Client in order to manage cookies across HTTP requests and responses.

The class contains an array of Zend_Http_Cookie objects. Cookies can be added to the jar automatically from a request or manually. Then, the jar can find and return the cookies needed for a specific HTTP request.

A special parameter can be passed to all methods of this class that return cookies: Cookies can be returned either in their native form (as Zend_Http_Cookie objects) or as strings - the later is suitable for sending as the value of the "Cookie" header in an HTTP request. You can also choose, when returning more than one cookie, whether to get an array of strings (by passing Zend_Http_CookieJar::COOKIE_STRING_ARRAY) or one unified string for all cookies (by passing Zend_Http_CookieJar::COOKIE_STRING_CONCAT).

link for some specs.
category Zend
package Zend_Http
subpackage CookieJar
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Construct a new CookieJar object

__construct() 

Add a cookie to the jar. Cookie should be passed either as a Zend_Http_Cookie object or as a string - in which case an object is created from the string.

addCookie(\Zend_Http_Cookie|string $cookie, \Zend_Uri_Http|string $ref_uri = null, boolean $encodeValue = true

Parameters

$cookie

\Zend_Http_Cookiestring

$ref_uri

\Zend_Uri_Httpstring

Optional reference URI (for domain, path, secure)

$encodeValue

boolean

Parse an HTTP response, adding all the cookies set in that response to the cookie jar.

addCookiesFromResponse(\Zend_Http_Response $response, \Zend_Uri_Http|string $ref_uri, boolean $encodeValue = true

Parameters

$response

\Zend_Http_Response

$ref_uri

\Zend_Uri_Httpstring

Requested URI

$encodeValue

boolean

Required by Countable interface

count() : integer

Returns

integer

Create a new CookieJar object and automatically load into it all the cookies set in an Http_Response object. If $uri is set, it will be considered as the requested URI for setting default domain and path of the cookie.

fromResponse(\Zend_Http_Response $response, $ref_uri) : \Zend_Http_CookieJar
Static
todo Add the $uri functionality.

Parameters

$response

\Zend_Http_Response

HTTP Response object

$ref_uri

Returns

\Zend_Http_CookieJar

Get all cookies in the cookie jar as an array

getAllCookies(integer $ret_as = self::COOKIE_OBJECT) : array | string

Parameters

$ret_as

integer

Whether to return cookies as objects of Zend_Http_Cookie or as strings

Returns

arraystring

Get a specific cookie according to a URI and name

getCookie(\Zend_Uri_Http|string $uri, string $cookie_name, integer $ret_as = self::COOKIE_OBJECT) : \Zend_Http_Cookie | string

Parameters

$uri

\Zend_Uri_Httpstring

The uri (domain and path) to match

$cookie_name

string

The cookie's name

$ret_as

integer

Whether to return cookies as objects of Zend_Http_Cookie or as strings

Returns

\Zend_Http_Cookiestring

Required by IteratorAggregate interface

getIterator() : \ArrayIterator

Returns

\ArrayIterator

Return an array of all cookies matching a specific request according to the request URI, whether session cookies should be sent or not, and the time to consider as "now" when checking cookie expiry time.

getMatchingCookies(string|\Zend_Uri_Http $uri, boolean $matchSessionCookies = true, integer $ret_as = self::COOKIE_OBJECT, integer $now = null) : array | string

Parameters

$uri

string\Zend_Uri_Http

URI to check against (secure, domain, path)

$matchSessionCookies

boolean

Whether to send session cookies

$ret_as

integer

Whether to return cookies as objects of Zend_Http_Cookie or as strings

$now

integer

Override the current time when checking for expiry time

Returns

arraystring

Tells if the jar is empty of any cookie

isEmpty() : boolean

Returns

boolean

Empties the cookieJar of any cookie

reset() : \Zend_Http_CookieJar

Returns

\Zend_Http_CookieJar

Helper function to recursivly flatten an array. Shoud be used when exporting the cookies array (or parts of it)

_flattenCookiesArray(\Zend_Http_Cookie|array $ptr, integer $ret_as = self::COOKIE_OBJECT) : array | string

Parameters

$ptr

\Zend_Http_Cookiearray

$ret_as

integer

What value to return

Returns

arraystring

Return a subset of the cookies array matching a specific domain

_matchDomain(string $domain) : array

Parameters

$domain

string

Returns

array

Return a subset of a domain-matching cookies that also match a specified path

_matchPath($domains, string $path) : array

Parameters

$domains

$path

string

Returns

array

 Properties

 

The Zend_Http_Cookie array

$_rawCookies : array

Default

array()
 

Array storing cookies

$cookies : array

Default

array()

Cookies are stored according to domain and path: $cookies

  • www.mydomain.com
    • /
      • cookie1
      • cookie2
    • /somepath
      • othercookie
  • www.otherdomain.net
    • /
      • alsocookie

 Constants