Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 28th, 2005, 3:18 PM   #1
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
session timeout detecting?

hi,

i have a membership script that updates a value stored in a database and sets session data when a user logins in these values are used for the who's online part of my script.
When the user clicks on the logout button it updates the database again and changes the value back to 0 and destroys the session data but the problem is if a user just leaves the site without logging out the value reamins set to 1,

my question is, is it possible to detect if the user has left the site without logging out by detecting if the session data has timed out?

thanx in advanced

magic e
magic_e is offline   Reply With Quote
Old Jun 5th, 2005, 2:32 AM   #2
LiveWire
Newbie
 
LiveWire's Avatar
 
Join Date: Jun 2005
Location: Flordia
Posts: 5
Rep Power: 0 LiveWire is on a distinguished road
The way i did this on one of my scripts was, i had a global file. Inside that global file i used:

[php]
require_once('./functions/sessions.php');
[/php]

Now anytime a user clicked on a link the global file would run which would run the seesions.php file. Anyways, inside the sessions.php file there was a query that would run and set the last activity of the user, using the current time. Inside my admincp area i had a cookietimeout field that i can specifity x mintues.



Therefor you can do something similar to this
[php]
define('TIMENOW', time());
if (TIMENOW - $user['lastactivity'] > $admincp['cookietimeout'])
{
// destroy cookie settings here
}
[/php]

Hope this gets you on the right track.
__________________
I had a monumental idea this morning, but I didn't like it.
LiveWire is offline   Reply With Quote
Old Jun 5th, 2005, 6:43 AM   #3
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Actually the problem I believe is that once the user leaves the site there is no code being executed at the request of the user which means the value in the database just remains as '1'.

There are two ways you can go about doing this... when the user logs in, and everytime the request a page update the session in the database with a timestamp that represents there last access... if soo much time has elapsed since last timestamp force them to log in again, this however will not remove the '1' from the database, but in all reality it would not matter since you could control and prevent the session from going stale anyway.

If you wanted to actually reset the '1' to '0' or manually destroy other data what you will need to do is run a backend script through a cron job or as a process which sleeps for so much time and than checks all the session timestamps in the database, anything that has timeout is immediatly reset and destroyed.
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Jun 29th, 2005, 4:50 PM   #4
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
sry for not replying and thanx for the replys

but i decided to change the why it showed users to be online


thanx again


Magic E
magic_e is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:32 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC