vendor/symfony/http-foundation/Session/SessionUtils.php line 52

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpFoundation\Session;
  11. /**
  12.  * Session utility functions.
  13.  *
  14.  * @author Nicolas Grekas <p@tchwork.com>
  15.  * @author RĂ©mon van de Kamp <rpkamp@gmail.com>
  16.  *
  17.  * @internal
  18.  */
  19. final class SessionUtils
  20. {
  21.     /**
  22.      * Finds the session header amongst the headers that are to be sent, removes it, and returns
  23.      * it so the caller can process it further.
  24.      */
  25.     public static function popSessionCookie(string $sessionNamestring $sessionId): ?string
  26.     {
  27.         $sessionCookie null;
  28.         $sessionCookiePrefix sprintf(' %s='urlencode($sessionName));
  29.         $sessionCookieWithId sprintf('%s%s;'$sessionCookiePrefixurlencode($sessionId));
  30.         $otherCookies = [];
  31.         foreach (headers_list() as $h) {
  32.             if (!== stripos($h'Set-Cookie:')) {
  33.                 continue;
  34.             }
  35.             if (11 === strpos($h$sessionCookiePrefix11)) {
  36.                 $sessionCookie $h;
  37.                 if (11 !== strpos($h$sessionCookieWithId11)) {
  38.                     $otherCookies[] = $h;
  39.                 }
  40.             } else {
  41.                 $otherCookies[] = $h;
  42.             }
  43.         }
  44.         if (null === $sessionCookie) {
  45.             return null;
  46.         }
  47.         header_remove('Set-Cookie');
  48.         foreach ($otherCookies as $h) {
  49.             header($hfalse);
  50.         }
  51.         return $sessionCookie;
  52.     }
  53. }