you can check this link.. http://bakery.cakephp.org/articles/imran7000/2010/03/12/check-member-user-online-or-offline-status
HTTP is stateless, therefore it is hard to determine whether someone is "online" or "offline". This needs to be done with some sort of session tracking and a "last click" time in the user's or session's table. You can then query it to find when their last click was.
yep Sam is right .You should have something to save the state of user.something like a session table.And u know I've a pretty no.f time Good luck
Well the best bet would be store Active User sessions in DB and check active status directly from DB during each page load.
Just put an extra field in your profile table ie, status . And when a user logins ,update the table with a status 'ON' in that field and when the user logsout similarly update that field to 'OFF'. So, to show online members just put a select query with condition 'where status='ON'' It will do...
Hmm what happens when a user does not logout but closes the website (and goes to another...) would he/she still be 'online'?
Personally I think the best way would be to have a table for a user where each time a user accesses a page, the php page inserts NOW() into a date time field, and then to determine if they are logged in or not the php page would say if(time() - $lastaccess < 15 minute) then logged in is true. Note this isn't the actual code you'd need to use. If you'd like me to write a simple function like this, just pm me.
you can have a separate table with session id, user id, time. when someone access your site you can check: if there is no session, then insert session id, user id (or null if is anonymous) and time. if is already a session for that visitor, you update the time field. alter that you can delete all rows with a period of inactivity.