Skip to content

Commit 940167f

Browse files
bug #35656 [HttpFoundation] Fixed session migration with custom cookie lifetime (Guite)
This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [HttpFoundation] Fixed session migration with custom cookie lifetime | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #28577 | License | MIT | Doc PR | This PR adds the fix proposed in symfony/symfony#28577 (comment) Commits ------- 3e824de385 [HttpFoundation] Fixed session migration with custom cookie lifetime
2 parents 7fd8435 + 9a692b6 commit 940167f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Session/Storage/NativeSessionStorage.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ public function regenerate($destroy = false, $lifetime = null)
213213
return false;
214214
}
215215

216-
if (null !== $lifetime) {
216+
if (null !== $lifetime && $lifetime != ini_get('session.cookie_lifetime')) {
217+
$this->save();
217218
ini_set('session.cookie_lifetime', $lifetime);
219+
$this->start();
218220
}
219221

220222
if ($destroy) {

Tests/Session/Storage/NativeSessionStorageTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ public function testRegenerateDestroy()
123123
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
124124
}
125125

126+
public function testRegenerateWithCustomLifetime()
127+
{
128+
$storage = $this->getStorage();
129+
$storage->start();
130+
$id = $storage->getId();
131+
$lifetime = 999999;
132+
$storage->getBag('attributes')->set('legs', 11);
133+
$storage->regenerate(false, $lifetime);
134+
$this->assertNotEquals($id, $storage->getId());
135+
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
136+
$this->assertEquals($lifetime, ini_get('session.cookie_lifetime'));
137+
}
138+
126139
public function testSessionGlobalIsUpToDateAfterIdRegeneration()
127140
{
128141
$storage = $this->getStorage();

0 commit comments

Comments
 (0)