Recently, a PHP project used the function of limiting the login time. For example, if the user logs into the system for 60 minutes and there is no operation, it will automatically log out. I searched the Internet and collected the following methods for reference.
The first method is to set the php.ini configuration file and 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:
Copy code The code is as follows:
ini_set('session.gc_maxlifetime', "3600"); // Seconds
ini_set("session.cookie_lifetime", "3600"); // Seconds
The second method is to set the Session timestamp, such as the following method.
When the login is successful, set the timestamp to 1 hour later than the current time, $_SESSION['expiretime'] = time() + 3600;. Use the following code to check user login status:
Copy code The code is as follows:
if(isset($_SESSION['expiretime '])) {
if($_SESSION['expiretime'] < time()) {
unset($_SESSION['expiretime']);
header('Location: logout.php? TIMEOUT'); // Log out
>}
According to laruence’s article "How to set up a Session with a strict 30-minute expiration", we can combine the first and second methods to finally determine the session timeout.
http://www.bkjia.com/PHPjc/781415.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/781415.htmlTechArticleRecently, a PHP project used the function of limiting the login time. For example, if the user logs in to the system for 60 minutes and there is no operation, Automatically exit. I searched the Internet and found the following methods for reference...