I need to keep a session alive for 30 minutes and then destroy it.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Is this to log the user out after a set time? Setting the session creation time (or an expiry time) when it is registered, and then checking that on each page load could handle that.
E.g.:
Edit: I've got a feeling you mean something else though.
You can scrap sessions after a certain lifespan by using the
session.gc_maxlifetime
ini setting:Edit: ini_set('session.gc_maxlifetime', 60*30);
Simple way of PHP session expiry in 30 minutes.
Note : if you want to change the time, just change the 30 with your desired time and do not change * 60: this will gives the minutes.
In minutes : (30 * 60)
In days : (n * 24 * 60 * 60 ) n = no of days
Login.php
HomePage.php
LogOut.php
This post shows a couple of ways of controlling the session timeout: http://bytes.com/topic/php/insights/889606-setting-timeout-php-sessions
IMHO the second option is a nice solution:
Well i understand the aboves answers are correct but they are on application level, why don't we simply use
.htaccess
file to set the expire time ?Please use following block of code in your include file which loaded in every pages.
Use this class for 30 min