You are here

function HTTP_Response::_parseCookie in Flickr API 5

Parse a Set-Cookie header to fill $_cookies array

@access private

Parameters

string value of Set-Cookie header:

1 call to HTTP_Response::_parseCookie()
HTTP_Response::_processHeader in phpFlickr/PEAR/HTTP/Request.php
Processes the response header

File

phpFlickr/PEAR/HTTP/Request.php, line 1293

Class

HTTP_Response
Response class to complement the Request class

Code

function _parseCookie($headervalue) {
  $cookie = array(
    'expires' => null,
    'domain' => null,
    'path' => null,
    'secure' => false,
  );

  // Only a name=value pair
  if (!strpos($headervalue, ';')) {
    $pos = strpos($headervalue, '=');
    $cookie['name'] = trim(substr($headervalue, 0, $pos));
    $cookie['value'] = trim(substr($headervalue, $pos + 1));

    // Some optional parameters are supplied
  }
  else {
    $elements = explode(';', $headervalue);
    $pos = strpos($elements[0], '=');
    $cookie['name'] = trim(substr($elements[0], 0, $pos));
    $cookie['value'] = trim(substr($elements[0], $pos + 1));
    for ($i = 1; $i < count($elements); $i++) {
      if (false === strpos($elements[$i], '=')) {
        $elName = trim($elements[$i]);
        $elValue = null;
      }
      else {
        list($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
      }
      $elName = strtolower($elName);
      if ('secure' == $elName) {
        $cookie['secure'] = true;
      }
      elseif ('expires' == $elName) {
        $cookie['expires'] = str_replace('"', '', $elValue);
      }
      elseif ('path' == $elName || 'domain' == $elName) {
        $cookie[$elName] = urldecode($elValue);
      }
      else {
        $cookie[$elName] = $elValue;
      }
    }
  }
  $this->_cookies[] = $cookie;
}