简体   繁体   中英

PHP stop the session from ending / logging the user out

I am wanting to keep the session/user logged in for at least 3600000 seconds, I have tried multiple ways of PHP and still after looking at highly voted answers...it still wont work and logs the user out after labout 5-10 minutes.

PHP

<?php
ini_set('session.cookie_lifetime', 60 * 60 * 24 * 7);
ini_set('session.gc_maxlifetime', 3600000);
session_start();


if(!isset($_SESSION["username"])){
header("Location: admin-login.php");
exit(); }

if (isset($_SESSION['username']) && (time() - $_SESSION['username'] > 3600000)) {
    session_unset();     // unset $_SESSION variable for the run-time 
    session_destroy();   // destroy session data in storage
}
$_SESSION['username'] = time(); // update last activity time stamp
ini_set('session.cookie_lifetime', 60 * 60 * 24 * 7);

用它代替session.gc_maxlifetime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM