Page 1 of 1
Automatic logout
Posted: Wed Aug 03, 2011 2:26 am
by gregerst
Hi,
I have a questions concerning how to do automatic logout from webb application when say not used it for 15 minutes or so. My application is written in Dreamweaver 5.5 and all pages are PHP scrips,
Hope you can help me to do this.
Thanks in advance
Greger Stag
Re: Automatic logout
Posted: Wed Aug 03, 2011 8:20 am
by social_experiment
The Manual wrote:
session.gc_maxlifetime integer
session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start.
I'm not sure if this is correct but what you have in mind is most likely handled by a setting in the php.ini file

Re: Automatic logout
Posted: Wed Aug 03, 2011 9:30 am
by gregerst
Thank's for this ide. I have my application hosted at ONE.com (webbhotel). What I will have is that when a user have doing nothing say for 15 minutes or so, I will have a jump to one of my script called logout.php
I look in PHP.ini for the "session.gc.maxlifetime" but I think thats not the answer to my problem or?
/Greger
Re: Automatic logout
Posted: Wed Aug 03, 2011 12:12 pm
by social_experiment
gregerst wrote:Thank's for this ide. I have my application hosted at ONE.com (webbhotel). What I will have is that when a user have doing nothing say for 15 minutes or so, I will have a jump to one of my script called logout.php
I look in PHP.ini for the "session.gc.maxlifetime" but I think thats not the answer to my problem or?

No reference to an ide in the reply. From my understanding of session.gc.maxlifetime (which might be incorrect) it sees the data (session data) as garbage and cleans it up, meaning whatever is in the session at that time, will be cleared away. So if you have any authorised info stored in the session, it will be cleared and the user will be logged out.
Re: Automatic logout
Posted: Wed Aug 03, 2011 4:00 pm
by flying_circus
I think the better way would be to use a timestamp. This way you can maintain a user session, but expire a login.
This is usefull when you want to log a user out of their account, but maybe still show them whats in their shopping cart in the unsecure parts of your store (or whatever).
Code: Select all
<?php
$maxlife = 900; // 15 Minutes
session_start();
if(isset($_SESSION['last_accessed'])) {
if($_SESSION['last_accessed'] < (time() - $maxlife)) {
# Session Expired
logout();
} else {
# Session Still Active
$_SESSION['last_accessed'] = time();
}
} else {
# New Session
$_SESSION['last_accessed'] = time();
}
?>
Re: Automatic logout
Posted: Wed Aug 03, 2011 8:42 pm
by McInfo
gregerst wrote:Thank's for this ide.
social_experiment wrote: 
No reference to an ide in the reply.
I think Greger meant to write "idea".
Re: Automatic logout
Posted: Thu Aug 04, 2011 2:44 am
by gregerst
Thank's for all good answers. I will test Flying_cicus code and se what happends.
Thanks to all of you.

Re: Automatic logout
Posted: Thu Aug 04, 2011 5:28 am
by social_experiment
@McInfo : Good point

My bad