56 $this->_cookies =& $storageArray;
72 $urlParts = parse_url($request_url);
73 $defaultDomain = $urlParts[
'host'];
77 foreach ($cookies as $cookie) {
103 if (!count($this->_cookies)) {
108 $target = parse_url($request_url);
109 if ($target ===
false) {
115 $matching_cookies = array();
116 foreach ($this->_cookies as $key => $cookie) {
118 $matching_cookies[$cookie[
'name']] = $cookie[
'value'];
121 return $matching_cookies;
139 foreach ( $header as $line ) {
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;
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)