55 $this->_cookies = &$storageArray;
71 $urlParts = parse_url($request_url);
72 $defaultDomain = $urlParts[
'host'];
77 foreach ($cookies as $cookie) {
103 if (!count($this->_cookies)) {
108 $target = parse_url($request_url);
115 $matching_cookies = array();
116 foreach ($this->_cookies as
$key => $cookie) {
118 $matching_cookies[$cookie[
'name']] = $cookie[
'value'];
121 return $matching_cookies;
140 if (preg_match(
'/^Set-Cookie2?: /i', $line)) {
162 if (!$defaultDomain) {
164 '$defaultDomain was not provided.' 170 'domain' => $defaultDomain,
175 $line = preg_replace(
'/^Set-Cookie2?: /i',
'', trim($line));
178 $line = trim($line,
';');
187 $attributeStrings = explode(
';', $line);
189 foreach ($attributeStrings as $attributeString) {
191 $attributeParts = explode(
'=', $attributeString, 2);
193 $attributeName = trim($attributeParts[0]);
194 $attributeNameLC = strtolower($attributeName);
196 if (isset($attributeParts[1])) {
197 $attributeValue = trim($attributeParts[1]);
199 if (strpos($attributeValue,
'"') === 0) {
200 $attributeValue = trim($attributeValue,
'"');
202 $attributeValue = str_replace(
'\"',
'"', $attributeValue);
205 $attributeValue = null;
208 switch ($attributeNameLC) {
210 $cookie[
'expires'] = strtotime($attributeValue);
213 $cookie[
'max-age'] = (int) $attributeValue;
215 if ($cookie[
'max-age']) {
216 $cookie[
'expires'] = time() + $cookie[
'max-age'];
220 $cookie[
'expires'] = time() - 1;
224 $cookie[
'secure'] =
true;
234 $cookie[$attributeNameLC] = $attributeValue;
237 $cookie[
'name'] = $attributeName;
238 $cookie[
'value'] = $attributeValue;
258 $this->_cookies[] = $cookie;
272 if (!isset($cookie[
'domain'])
273 || !isset($cookie[
'path'])
274 || !isset($cookie[
'path'])
279 foreach ($this->_cookies as
$key => $old_cookie) {
280 if ($cookie[
'domain'] == $old_cookie[
'domain']
281 && $cookie[
'path'] == $old_cookie[
'path']
282 && $cookie[
'name'] == $old_cookie[
'name']
284 unset($this->_cookies[
$key]);
298 foreach ($this->_cookies as
$key => $cookie) {
299 if (isset($cookie[
'expires']) && $cookie[
'expires'] < time()) {
300 unset($this->_cookies[
$key]);
319 '$target must be an array of URL attributes as generated by parse_url().' 324 '$target must be an array of URL attributes as generated by parse_url().' 329 if ($cookie[
'secure'] &&
$target[
'scheme'] !=
'https') {
335 if (strpos($cookie[
'domain'],
'.') === 0) {
337 if (substr($cookie[
'domain'], 1) ==
$target[
'host']) {
342 $pos = strripos(
$target[
'host'], $cookie[
'domain']);
347 if ($pos + strlen($cookie[
'domain']) != strlen(
$target[
'host'])) {
353 $hostname = substr(
$target[
'host'], 0, $pos);
354 if (strpos($hostname,
'.') !==
false) {
361 if (strcasecmp(
$target[
'host'], $cookie[
'domain']) !== 0) {
367 if (isset($cookie[
'ports'])
368 && !in_array(
$target[
'port'], $cookie[
'ports'])
374 if (strpos(
$target[
'path'], $cookie[
'path']) !== 0) {
parseCookieHeader($line, $defaultDomain)
Parse a single cookie header line.
cookieMatchesTarget($cookie, $target)
Answer true if cookie is applicable to a target.
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
__construct(array &$storageArray)
Create a new cookie jar by passing it a reference to an array in which it should store cookies...
static trace($str)
This method is used to log something in debug mode.
parseCookieHeaders($header, $defaultDomain)
Parse Cookies without PECL From the comments in http://php.net/manual/en/function.http-parse-cookie.php.
Exception that denotes invalid arguments were passed.
storeCookie($cookie)
Add, update, or remove a cookie.
expireCookies()
Go through our stored cookies and remove any that are expired.
getCookies($request_url)
Retrieve cookies applicable for a web service request.
storeCookies($request_url, $response_headers)
Store cookies for a web service request.
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
discardCookie($cookie)
Discard an existing cookie.
This class provides access to service cookies and handles parsing of response headers to pull out coo...