![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Jun 2005
Location: Flordia
Posts: 5
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|