Skip to content

Commit 544d9e6

Browse files
committed
Session: regenerateId() refactoring
1 parent 3ea16d9 commit 544d9e6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Http/Session.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function start(): void
114114
// regenerate empty session
115115
if (empty($nf['Time'])) {
116116
$nf['Time'] = time();
117-
$this->regenerated = true;
117+
$this->regenerateId();
118118
}
119119

120120
// resend cookie
@@ -139,11 +139,6 @@ public function start(): void
139139
}
140140
}
141141

142-
if ($this->regenerated) {
143-
$this->regenerated = false;
144-
$this->regenerateId();
145-
}
146-
147142
register_shutdown_function([$this, 'clean']);
148143
}
149144

@@ -204,7 +199,10 @@ public function exists(): bool
204199
*/
205200
public function regenerateId(): void
206201
{
207-
if (self::$started && !$this->regenerated) {
202+
if ($this->regenerated) {
203+
return;
204+
}
205+
if (self::$started) {
208206
if (headers_sent($file, $line)) {
209207
throw new Nette\InvalidStateException('Cannot regenerate session ID after HTTP headers have been sent' . ($file ? " (output started at $file:$line)." : '.'));
210208
}
@@ -215,6 +213,8 @@ public function regenerateId(): void
215213
$backup = $_SESSION;
216214
session_start();
217215
$_SESSION = $backup;
216+
} else {
217+
session_id(session_create_id());
218218
}
219219
$this->regenerated = true;
220220
}

0 commit comments

Comments
 (0)