From d4707eb595cb47cd925e09f66f7ea4673075dda2 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Tue, 20 Jun 2023 18:53:11 -0500 Subject: [PATCH] Update setcookie() for PHP8 compatibility --- lib/Session.php | 2 +- www/settings/post.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Session.php b/lib/Session.php index da2bb449..434c21d4 100644 --- a/lib/Session.php +++ b/lib/Session.php @@ -82,7 +82,7 @@ class Session extends PropertiesBase{ } public static function SetSessionCookie(string $sessionId): void{ - setcookie('sessionid', $sessionId, time() + 60 * 60 * 24 * 14 * 1, '/', SITE_DOMAIN, true, false); // Expires in two weeks + setcookie('sessionid', $sessionId, ['expires' => strtotime('+1 week'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks } public static function Get(?string $sessionId): Session{ diff --git a/www/settings/post.php b/www/settings/post.php index 1b520ce5..94ea53d3 100644 --- a/www/settings/post.php +++ b/www/settings/post.php @@ -7,7 +7,7 @@ $hideDonationAlert = HttpInput::Bool(POST, 'hide-donation-alert'); $colorScheme = HttpInput::Str(POST, 'color-scheme'); if($hideDonationAlert !== null){ - setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', strtotime('+1 month'), '/', '', true, true); + setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', ['expires' => strtotime('+1 month'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); } if($colorScheme !== null){ @@ -17,10 +17,10 @@ if($colorScheme !== null){ if($colorScheme == 'auto'){ // Delete the cookie; auto is the default - setcookie('color-scheme', '', 0, '/', '', true, true); + setcookie('color-scheme', '', ['expires' => 0, 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); } else{ - setcookie('color-scheme', $colorScheme, strtotime('+1 year'), '/', '', true, true); + setcookie('color-scheme', $colorScheme, ['expires' => strtotime('+1 year'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); } }