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
9 declare(strict_types=1);
11 namespace Laminas\Diactoros;
13 use function preg_match_all;
14 use function urldecode;
17 * Parse a cookie header according to RFC 6265.
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.
22 * @param string $cookieHeader A string cookie header value.
23 * @return array key/value cookie pairs.
25 function parseCookieHeader($cookieHeader) : array
29 (?P<name>[!#$%&\'*+-.0-9A-Z^_`a-z|~]+)
32 (?P<value>[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*)
35 )x', $cookieHeader, $matches, PREG_SET_ORDER);
39 foreach ($matches as $match) {
40 $cookies[$match['name']] = urldecode($match['value']);