Open Journal Systems  3.3.0
SessionUtils.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
22 final class SessionUtils
23 {
28  public static function popSessionCookie(string $sessionName, string $sessionId): ?string
29  {
30  $sessionCookie = null;
31  $sessionCookiePrefix = sprintf(' %s=', urlencode($sessionName));
32  $sessionCookieWithId = sprintf('%s%s;', $sessionCookiePrefix, urlencode($sessionId));
33  $otherCookies = [];
34  foreach (headers_list() as $h) {
35  if (0 !== stripos($h, 'Set-Cookie:')) {
36  continue;
37  }
38  if (11 === strpos($h, $sessionCookiePrefix, 11)) {
39  $sessionCookie = $h;
40 
41  if (11 !== strpos($h, $sessionCookieWithId, 11)) {
42  $otherCookies[] = $h;
43  }
44  } else {
45  $otherCookies[] = $h;
46  }
47  }
48  if (null === $sessionCookie) {
49  return null;
50  }
51 
52  header_remove('Set-Cookie');
53  foreach ($otherCookies as $h) {
54  header($h, false);
55  }
56 
57  return $sessionCookie;
58  }
59 }
Symfony\Component\HttpFoundation\Session
Symfony\Component\HttpFoundation\Session\SessionUtils
Definition: SessionUtils.php:22
Symfony\Component\HttpFoundation\Session\SessionUtils\popSessionCookie
static popSessionCookie(string $sessionName, string $sessionId)
Definition: SessionUtils.php:28