donboe — 2014-06-26T05:50:34-04:00 — #1
For a forum I am lookng for a simple but accurate online/offline check functionality so users can see which user is online or offline. Are there some ready mad scripts or does anyone know of a good tutorial to accomplish this?
Thank you in advance!
volter9 — 2014-06-26T15:07:11-04:00 — #2
Which type of forum do you have? Some kind of phpBB or custom one that you wrote yourself?
And do you want to make it dynamic (JS) or just static render of on/off line users?
donboe — 2014-06-26T17:52:27-04:00 — #3
It is custom. And i would like to have it with js zo dynamic. I have been searchin for quite some tiime
volter9 — 2014-06-26T18:49:19-04:00 — #4
It's quite easy to realize, all you need is to create another two fields in table with users: online (tinyint) and last_online (timestamp).
Each time (or each second time) user enters on the page you update the last_online to now() and set online to 1, like that:
UPDATE users SET last_online = NOW(), online = 1 WHERE id = $user_id
And execute another SQL statement to put offline users who are not online:
UPDATE users SET online = 0 WHERE online = 1 AND last_online < NOW() - 120
Where 120 is amount of seconds you want to put users in offline mode.
Then you can select users by online field. However I don't understand where do you want to display this data. Reply please.
users can see which user is online or offline
Do you want it display in bottom of main page on forum, or you have some kind of popup with info about user, or you want to display data on user's page or even in the topic section?
donboe — 2014-06-27T02:57:53-04:00 — #5
Thank you again for the reply. Very very helpful. Gonna work on it right away!
About the above question. I just want a online or offline icon next to their profile
pullo — 2014-06-27T04:48:06-04:00 — #6
It seems volter9 already gave you your answer, but I just wanted to give Offline.js (a library to automatically alert your users when they've lost internet connectivity) a mention.
donboe — 2014-06-28T03:36:39-04:00 — #7
Yes he indeed did Pullo. Thank you anyway for the tip about Offline.js. I am going to look into that