How to set the session timeout in php: You can use the ini_set() function to change the attribute value of the current context to achieve the purpose of setting the session timeout, such as: [ini_set('session.gc_maxlifetime', " 3600");].
First method:
(Recommended tutorial:php graphic tutorial)
Set the php.ini configuration file, set the session.gc_maxlifetime and session.cookie_lifetime node attribute values. Of course, you can also use the ini_set function to change the attribute values of the current context environment:
ini_set('session.gc_maxlifetime', "3600"); // 秒 ini_set("session.cookie_lifetime","3600"); // 秒
Second method:
Set Session timestamp
When the login is successful, set the timestamp to 1 hour after the current time, $_SESSION['expiretime'] = time() 3600;.
(Video tutorial recommendation:php video tutorial)
Use the following code to check the user login status:
if(isset($_SESSION['expiretime'])) { if($_SESSION['expiretime'] < time()) { unset($_SESSION['expiretime']); header('Location: logout.php?TIMEOUT'); // 登出 exit(0); } else { $_SESSION['expiretime'] = time() + 3600; // 刷新时间戳 } }
The above is the detailed content of How to set session timeout in php. For more information, please follow other related articles on the PHP Chinese website!