Online/ofline status check

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!

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?

It is custom. And i would like to have it with js zo dynamic. I have been searchin for quite some tiime

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?

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

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.

Yes he indeed did Pullo. Thank you anyway for the tip about Offline.js. I am going to look into that