Automatic logout
Moderator: General Moderators
Automatic logout
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
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
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Automatic logout
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 fileThe 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Automatic logout
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
I look in PHP.ini for the "session.gc.maxlifetime" but I think thats not the answer to my problem or?
/Greger
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Automatic logout
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?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: Automatic logout
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).
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
gregerst wrote:Thank's for this ide.
I think Greger meant to write "idea".social_experiment wrote:No reference to an ide in the reply.
Re: Automatic logout
Thank's for all good answers. I will test Flying_cicus code and se what happends.
Thanks to all of you.
Thanks to all of you.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Automatic logout
@McInfo : Good point
My bad
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering