View Full Version : users online
04-19-2003, 03:32 PM
i'm able to code to track users' movements throughout the site, a bunch of login details, etc. but if i want to have a "Users online" feature, i'll need to know when users logs off. i'll have a 'logoff' form of course, which will update the 'user' table in the database to 'not logged in', but lots of people don't bother to sign off. they just close the browser window or disconnect. how can i track when they've done this?
i'm using sessions mainly.
how can i track when a user has stopped being logged in?
04-19-2003, 04:17 PM
hmm... well from the sounds of what you describe... you're using sessions to see where everybody is, ay?... so i'll presume "logging out" ends the session, eh?... now... when you close the browser window that also ends the session, so either way, the session's been ended...
im no php guru though so i could be wrong ;)...
04-19-2003, 08:01 PM
lol i know the session'll be ended in any case..:p
the problem is how do i know when?
like if i close this Coding Forums window which i'm viewing right now, my session will end, then if anyone refreshes the CF home page, they won't see me in the list of current users online. how did the database get to know that I'm not online any more?
04-21-2003, 10:40 AM
There is a way to do it because my php teacher has done it on his site.
I have thought about how it could be done many times but have not asked him much about it but one of the other co-webmasters of the site said that the whois online code can not be made accurate to the second and has to made to an resonable time limit. In the url above, it's reset to 5 minutes per page click.
Now when he said that, the first thing that came to mind was ofc a cookie. I think if you set a page hit field in the database to generate a cookie that lasted for 5 minutes to be used in a whois online table, it should work. I've yet to have the nerve to toy with a code of my own to test it's possibilities but I would think that is your best bet.
04-21-2003, 12:35 PM
If you were to set it at say 15 minute intervals, of checking who is online. When a user visits a page, have it put a value in a database of time()+900, then when someone visits the page, get them to check the time.
If it is greater than the value entered, delete the value, else leave it there.
04-21-2003, 09:57 PM
on my sites i like to put 2 values on ever user record (in a database table).
last page = url of the last page they were at
last page date time = timestamp of when they clicked that page.
then for a 'who's online' section just do a lookup in your users table and limit to those users who have a
last page date time greater than whatever your session time out is.
You can also use this to show admins where folks that are logged in are.
Nice thing about this is you can make custom pages that sort users by last page hit day/time. to see who your active users are.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.