Session cookie fixes

main
Yasen Pramatarov 2024-07-02 20:04:12 +03:00
parent 637ac410f4
commit eff4b073f5
2 changed files with 8 additions and 7 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
$config = [ $config = [
'domain' => 'localhost', 'domain' => 'localhost.com',
'folder' => '/jilo-web/', 'folder' => '/jilo-web/',
'database' => '/home/yasen/work/code/git/lindeas-code/jilo-web/jilo-web.db', 'database' => '/home/yasen/work/code/git/lindeas-code/jilo-web/jilo-web.db',
]; ];

View File

@ -19,26 +19,27 @@ try {
// if remember_me is checked, max out the session // if remember_me is checked, max out the session
if (isset($_POST['remember_me'])) { if (isset($_POST['remember_me'])) {
// 30*24*60*60 = 30 days // 30*24*60*60 = 30 days
$cookie_lifetime = '30 * 24 * 60 * 60'; $cookie_lifetime = 30 * 24 * 60 * 60;
$gc_maxlifetime = '30 * 24 * 60 * 60'; $gc_maxlifetime = 30 * 24 * 60 * 60;
} else { } else {
// 0 - session end on browser close // 0 - session end on browser close
// 1440 - 24 minutes (default) // 1440 - 24 minutes (default)
$cookie_lifetime = '0'; $cookie_lifetime = 0;
$gc_maxlifetime = '1440'; $gc_maxlifetime = 1440;
} }
// set session lifetime // set session lifetime
ini_set('session.cookie_lifetime', $cookie_lifetime);
ini_set('session.gc_maxlifetime', $gc_maxlifetime); ini_set('session.gc_maxlifetime', $gc_maxlifetime);
session_set_cookie_params([ session_set_cookie_params([
'lifetime' => $lifetime, 'lifetime' => $cookie_lifetime,
'samesite' => 'Strict', 'samesite' => 'Strict',
'httponly' => true, 'httponly' => true,
'secure' => isset($_SERVER['HTTPS']), 'secure' => isset($_SERVER['HTTPS']),
'domain' => $config['domain'], 'domain' => $config['domain'],
'path' => $config['folder'] 'path' => $config['folder']
]); ]);
session_start();
// redirect to index // redirect to index
$_SESSION['notice'] = "Login successful"; $_SESSION['notice'] = "Login successful";
header('Location: index.php'); header('Location: index.php');