public static function parseCookieHeader ($hdr) {
    $cookies = array();
    $i = 0;
    $from = 0;
    $len = mb_strlen($hdr, 'latin1');
    $quoted = false;

    while ($i < $len) {
      if ('"' === $hdr[$i] && '\\' !== $elm[$i - 1]) {
        $quoted = !$quoted;
      }
      $elm = null;
      if (!$quoted && ',' === $hdr[$i]) {
        $chunk = mb_substr($hdr, $from, $i - $from, 'latin1');
        $elm = self::parseCookieElement($chunk);
        $from = $i + 1;

      } else if ($i === $len - 1) {
        $chunk = mb_substr($hdr, $from, $len - $from, 'latin1');
        $elm = self::parseCookieElement($chunk);
      }

      if (null !== $elm && isset($elm[self::COOKIE_NAME])) {
        $cookies[] = $elm;
      }
      $i += 1;
    } //end while
    return $cookies;
  }