Only create cookie when needed

This commit is contained in:
Miraty 2021-08-05 02:16:58 +02:00
parent 131f92b56c
commit 78932c0a7f

View file

@ -14,19 +14,28 @@ require "inc/reg.inc.php";
require "inc/pages.inc.php"; require "inc/pages.inc.php";
// Session initialisation (with cookies) // Session initialisation (with cookies)
session_start([ if (
'name' => 'niver', isset($_COOKIE['niver']) // Resume session
'sid_length' => 64, OR
'cookie_secure' => true, (SERVICE === "auth"
'cookie_httponly' => true, AND PAGE === "login"
'cookie_samesite' => 'Strict', AND isset($_POST['username']))
'cookie_path' => PREFIX . '/', ) {
'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days session_start([
'gc_maxlifetime' => 10800, 'name' => 'niver',
'use_strict_mode' => true, 'sid_length' => 64,
'use_cookies' => true, 'sid_bits_per_character' => 6,
'use_only_cookies' => true, 'cookie_secure' => true,
]); 'cookie_httponly' => true,
'cookie_samesite' => 'Strict',
'cookie_path' => PREFIX . '/',
'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days
'gc_maxlifetime' => 10800,
'use_strict_mode' => true,
'use_cookies' => true,
'use_only_cookies' => true,
]);
}
// Redirect to the login page if not logged in // Redirect to the login page if not logged in
if (SERVICE != "auth" AND !isset($_SESSION['username'])) { if (SERVICE != "auth" AND !isset($_SESSION['username'])) {