[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/laminas/laminas-diactoros/src/functions/ -> parse_cookie_header.php (source)

   1  <?php
   2  
   3  /**
   4   * @see       https://github.com/laminas/laminas-diactoros for the canonical source repository
   5   * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
   6   * @license   https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
   7   */
   8  
   9  declare(strict_types=1);
  10  
  11  namespace Laminas\Diactoros;
  12  
  13  use function preg_match_all;
  14  use function urldecode;
  15  
  16  /**
  17   * Parse a cookie header according to RFC 6265.
  18   *
  19   * PHP will replace special characters in cookie names, which results in other cookies not being available due to
  20   * overwriting. Thus, the server request should take the cookies from the request header instead.
  21   *
  22   * @param string $cookieHeader A string cookie header value.
  23   * @return array key/value cookie pairs.
  24   */
  25  function parseCookieHeader($cookieHeader) : array
  26  {
  27      preg_match_all('(
  28          (?:^\\n?[ \t]*|;[ ])
  29          (?P<name>[!#$%&\'*+-.0-9A-Z^_`a-z|~]+)
  30          =
  31          (?P<DQUOTE>"?)
  32              (?P<value>[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*)
  33          (?P=DQUOTE)
  34          (?=\\n?[ \t]*$|;[ ])
  35      )x', $cookieHeader, $matches, PREG_SET_ORDER);
  36  
  37      $cookies = [];
  38  
  39      foreach ($matches as $match) {
  40          $cookies[$match['name']] = urldecode($match['value']);
  41      }
  42  
  43      return $cookies;
  44  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer