Page 1 of 1

online members / guest's

Posted: Fri Jun 22, 2007 4:33 am
by spamyboy
I need to creat such think - how ? should I count all members online, then members sessions and minus them from all (to get only guest).
Myabe someone has some snippet's / tutorials about this - any help will be helpful.

Posted: Fri Jun 22, 2007 5:37 am
by Gente
You can do following.
1. Write a script, which insert a session_id to DB if it's not present there or update timestamp otherwise.
2. Call this script every X min. (sec.) with AJAX for example
3. Count of online users = count of DB records which were update during the last X min.

Posted: Fri Jun 22, 2007 5:47 am
by spamyboy
Got snippet of this kinde of script that use ajax ?

Posted: Fri Jun 22, 2007 6:20 am
by Gente
Script is very simple - if session_id is found in the table update time field with current time, if no add it. I don't think I should write PHP code here.
AJAX part is also very simple. Use can find a lot of examples is Google.
So you just need to use setTimeout() JS function
http://developer.mozilla.org/en/docs/DO ... setTimeout
Put the call of your AJAX request there and that is all.

Posted: Fri Jun 22, 2007 7:48 am
by superdezign
Or, even simpler, don't use AJAX at all. The only time that it matters how many people are online is when someone wants to look at it, so only update it on page loads.

Posted: Fri Jun 22, 2007 8:26 am
by Gente
superdezign wrote:Or, even simpler, don't use AJAX at all. The only time that it matters how many people are online is when someone wants to look at it, so only update it on page loads.
Yes it's possible but in this situation there will be another definition of "online user".
For example. I open some thread with 15 posts and read it for 30 minutes.
I won't be online for other users who just open a page.

Posted: Fri Jun 22, 2007 8:30 am
by superdezign
If your session expires, you're not online anyway.

Posted: Fri Jun 22, 2007 8:34 am
by Gente
Yes. You're right.
Ok, let's just notice that this is 2 different ways for different logic.

Posted: Fri Jun 22, 2007 8:54 am
by superdezign
Yezzir. ^_^

I always see the "non-AJAX" way, mostly because I've never used the XmlHTTP thing before. Maybe eventually, but not yet.

Posted: Fri Jun 22, 2007 8:57 am
by spamyboy
Thank you superdezign and you to Gente,
but I rather chose non-AJAX way. :)