fix: guard setcookie() and header() with headers_sent() check

functions.php and session.php are included from post.php inside footer,
after HTML output has started. setcookie() and header() calls without
headers_sent() guard produced 'Cannot modify header information' warnings.
This commit is contained in:
Divarion-D
2026-03-15 16:07:55 +03:00
parent e43d720fa4
commit 65ca557f3d
2 changed files with 12 additions and 4 deletions

View File

@@ -26,11 +26,15 @@ if (isset($_SESSION['hash'])) {
}
if (!empty($rUserInfo['hue']) && (!isset($_COOKIE['hue']) || $_COOKIE['hue'] != $rUserInfo['hue'])) {
setcookie('hue', $rUserInfo['hue'], time() + 604800);
if (!headers_sent()) {
setcookie('hue', $rUserInfo['hue'], time() + 604800);
}
}
if (!isset($_COOKIE['theme']) || $_COOKIE['theme'] != $rUserInfo['theme']) {
setcookie('theme', $rUserInfo['theme'], time() + 604800);
if (!headers_sent()) {
setcookie('theme', $rUserInfo['theme'], time() + 604800);
}
}
if (!isset($_COOKIE['lang']) || $_COOKIE['lang'] != $rUserInfo['lang']) {
@@ -46,7 +50,9 @@ if (isset($_SESSION['hash'])) {
unset($rUserInfo, $rPermissions);
destroySession();
header('Location: index');
if (!headers_sent()) {
header('Location: index');
}
exit();
}

View File

@@ -40,7 +40,9 @@ if (!isset($_SESSION['hash'])) {
exit();
}
header('Location: ./login?referrer=' . urlencode(basename($_SERVER['REQUEST_URI'], '.php')));
if (!headers_sent()) {
header('Location: ./login?referrer=' . urlencode(basename($_SERVER['REQUEST_URI'], '.php')));
}
exit();
}