Skip to content

Commit d0da8d0

Browse files
committed
Fix error - header already sent
1 parent 465683f commit d0da8d0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/JwtSession.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public function close()
7979
*/
8080
public function destroy($session_id)
8181
{
82+
if (headers_sent()) {
83+
return false;
84+
}
85+
8286
setcookie(self::COOKIE_PREFIX . $this->suffix, null);
8387
return true;
8488
}
@@ -170,8 +174,11 @@ public function write($session_id, $session_data)
170174
$data = $jwt->createJwtData($this->unSerializeSessionData($session_data), $this->timeOutMinutes * 60);
171175
$token = $jwt->generateToken($data);
172176

173-
setcookie(self::COOKIE_PREFIX . $this->suffix, $token);
177+
if (headers_sent()) {
178+
return false;
179+
}
174180

181+
setcookie(self::COOKIE_PREFIX . $this->suffix, $token);
175182
return true;
176183
}
177184

0 commit comments

Comments
 (0)