Hullo Shuriken, this is my first post here, so hopefully I'll be able to make a good impression to the forum people and help y'out.
I've got a 'Who's Online' module for my site, which counts the number of people (Members/Guests) browsing the page (counting number of IPs in actual fact), counting them as members if they're logged in and guests if they're not (that means people who aren't registered at all get counted as guests, too). Instead of actually logging people out as you suggested, I just give each member an 'expiry' time, a timestamp which when is reached, deletes the member from the 'users online' table. Yes, to do this, I use an extra database table. Every time it's run, the script checks if the user browsing the page is logged in or not, and updates his/her 'expiry' time as necessary. It then cleans out the table of all 'expired' IPs.
The output's something like
7 user(s) online:
3 member(s), 4 guest(s).
(Member 1's name), (Member 2's name), (Member 3's name)
etc ..
I assume that's what you want. How I do it :
-
I declare $exp, a variable which is equal to the current time plus how many more seconds I want the user to count as 'logged in'. I use time() + 300, for five minutes.
-
I check to see if the user's logged in or not. You'd use a session variable, a cookie or whatever else you use to check your online users.. I save the username as a variable.
-
I run a SELECT query on my 'whosonline' table, to see if the user's IP is in the table. If it is, I run an UPDATE query to update the user's expiry time. If not, I INSERT the user's details (for me, I need the IP, the user name, the user ID and the expiry time)
-
I then run a DELETE query on all IPs whose expiry times have passed the current limit (their timestamps are checked).
-
Another SELECT query on the table, getting all the usernames/IDs.
-
A simple while loop to print out the usernames online, plus the total guests/members. You could use mysql_num_rows to get the total number of users online, even though I do it a bit differently..
That's it, really. Reading over the post again, I'm ashamed to say it's probably a bit badly written, but I'm a newbie so maybe you'll forgive me. 😃 I dunno if this is what y'want, but it works perfectly for me.
Anyway, I'd be glad to help you out with source code and stuff, just ICQ me, email me (warbossalex@landofcypria.mkdi.net) or leave me a message here..
Cheers,
Alex ...
ps - my 'whosonline' table consists of the following:
userID(smallint(3)),
userName(varchar(50)),
IP(varchar 15),
time(varchar(10)) ..