56 $this->_cookies =& $storageArray;
72 $urlParts = parse_url($request_url);
73 $defaultDomain = $urlParts[
'host'];
78 foreach ($cookies as $cookie) {
104 if (!count($this->_cookies)) {
109 $target = parse_url($request_url);
110 if ($target ===
false) {
116 $matching_cookies = array();
117 foreach ($this->_cookies as $key => $cookie) {
119 $matching_cookies[$cookie[
'name']] = $cookie[
'value'];
122 return $matching_cookies;
140 foreach ( $header as $line ) {
141 if ( preg_match(
'/^Set-Cookie2?: /i', $line)) {
163 if (!$defaultDomain) {
165 '$defaultDomain was not provided.' 171 'domain' => $defaultDomain,
176 $line = preg_replace(
'/^Set-Cookie2?: /i',
'', trim($line));
179 $line = trim($line,
';');
188 $attributeStrings = explode(
';', $line);
190 foreach ( $attributeStrings as $attributeString ) {
192 $attributeParts = explode(
'=', $attributeString, 2);
194 $attributeName = trim($attributeParts[0]);
195 $attributeNameLC = strtolower($attributeName);
197 if (isset($attributeParts[1])) {
198 $attributeValue = trim($attributeParts[1]);
200 if (strpos($attributeValue,
'"') === 0) {
201 $attributeValue = trim($attributeValue,
'"');
203 $attributeValue = str_replace(
'\"',
'"', $attributeValue);
206 $attributeValue = null;
209 switch ($attributeNameLC) {
211 $cookie[
'expires'] = strtotime($attributeValue);
214 $cookie[
'max-age'] = (int)$attributeValue;
216 if ($cookie[
'max-age']) {
217 $cookie[
'expires'] = time() + $cookie[
'max-age'];
221 $cookie[
'expires'] = time() - 1;
225 $cookie[
'secure'] =
true;
235 $cookie[$attributeNameLC] = $attributeValue;
238 $cookie[
'name'] = $attributeName;
239 $cookie[
'value'] = $attributeValue;
259 $this->_cookies[] = $cookie;
274 if (!isset($cookie[
'domain'])
275 || !isset($cookie[
'path'])
276 || !isset($cookie[
'path'])
281 foreach ($this->_cookies as $key => $old_cookie) {
282 if ( $cookie[
'domain'] == $old_cookie[
'domain']
283 && $cookie[
'path'] == $old_cookie[
'path']
284 && $cookie[
'name'] == $old_cookie[
'name']
286 unset($this->_cookies[$key]);
300 foreach ($this->_cookies as $key => $cookie) {
301 if (isset($cookie[
'expires']) && $cookie[
'expires'] < time()) {
302 unset($this->_cookies[$key]);
319 if (!is_array($target)) {
321 '$target must be an array of URL attributes as generated by parse_url().' 324 if (!isset($target[
'host'])) {
326 '$target must be an array of URL attributes as generated by parse_url().' 331 if ($cookie[
'secure'] && $target[
'scheme'] !=
'https') {
337 if (strpos($cookie[
'domain'],
'.') === 0) {
339 if (substr($cookie[
'domain'], 1) == $target[
'host']) {
344 $pos = strripos($target[
'host'], $cookie[
'domain']);
349 if ($pos + strlen($cookie[
'domain']) != strlen($target[
'host'])) {
355 $hostname = substr($target[
'host'], 0, $pos);
356 if (strpos($hostname,
'.') !==
false) {
363 if (strcasecmp($target[
'host'], $cookie[
'domain']) !== 0) {
369 if (isset($cookie[
'ports'])
370 && !in_array($target[
'port'], $cookie[
'ports'])
376 if (strpos($target[
'path'], $cookie[
'path']) !== 0) {
parseCookieHeader($line, $defaultDomain)
cookieMatchesTarget($cookie, $target)
__construct(array &$storageArray)
parseCookieHeaders( $header, $defaultDomain)
storeCookies($request_url, $response_headers)