Skip to content

Commit 3d75d11

Browse files
committed
Session: do not regenerate session ID when is newly created
1 parent d9405cc commit 3d75d11

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/Http/Session.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function start()
7575

7676
$this->configure($this->options);
7777

78-
if (!session_id()) {
78+
if (!session_id()) { // session is started for first time
7979
$id = $this->request->getCookie(session_name());
8080
if (is_string($id) && preg_match('#^[0-9a-zA-Z,-]{22,256}\z#i', $id)) {
8181
session_id($id);
@@ -113,7 +113,9 @@ public function start()
113113
// regenerate empty session
114114
if (empty($nf['Time'])) {
115115
$nf['Time'] = time();
116-
$this->regenerated = true;
116+
if (!empty($id)) { // ensures that the session was created in strict mode (see use_strict_mode)
117+
$this->regenerateId();
118+
}
117119
}
118120

119121
// process meta metadata
@@ -135,11 +137,6 @@ public function start()
135137
}
136138
}
137139

138-
if ($this->regenerated) {
139-
$this->regenerated = false;
140-
$this->regenerateId();
141-
}
142-
143140
register_shutdown_function([$this, 'clean']);
144141
}
145142

tests/Http/Session.regenerateId().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $ref = 10;
2323

2424
$session->regenerateId();
2525
$newId = $session->getId();
26-
Assert::same($newId, $oldId); // new session is regenerated by $session->start()
26+
Assert::notSame($newId, $oldId);
2727
Assert::true(is_file($path . $newId));
2828

2929
$ref = 20;

0 commit comments

Comments
 (0)