Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,157,935 members, 7,835,118 topics. Date: Tuesday, 21 May 2024 at 05:00 AM

User Online /offline - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / User Online /offline (648 Views)

Ideas (legal) To Help You Make Money Online/offline As A Student / Need A Partner For An Online/offline Dating Service / W3school Offline Website (2) (3) (4)

(1) (Reply)

User Online /offline by Nobody: 5:53pm On Oct 04, 2011
am working on a script and i want this user is online after the users profile any idea out there
Re: User Online /offline by DualCore1: 9:23pm On Oct 04, 2011
This may help.

Have a field in the 'members' table called 'online'.
On successful login, update 'online' to yes.

On logout set 'online' to no.

To get all users online you select all from members where online = yes.


So what if the freak didn't log out properly?
Erm . . . go back to that 'members' table and add a timestamp field called 'last_activity' and set its default to current timestamp on update.

Add the following to a file you include in every page in your script
If logged in session isset
Update 'online' to yes . . . this automatically updates the last_activity field to current date and time.


Write a cron that runs at specified intervals and check all members that are online but have not been active in the last 30 minutes and sets their online status to no.

Query to get that is:
select * from members where online = 'yes' and  last_active < DATE_SUB(CURDATE(),INTERVAL 30 MINUTE)

OR this other query may just do it better than the select statement. . .
update members set online = 'no' where online = 'yes' and  last_active < DATE_SUB(CURDATE(),INTERVAL 30 MINUTE)


This should work but there's got to be something more performance effective out there. This is what I can think of now.
Re: User Online /offline by dhtml1(m): 10:53pm On Oct 04, 2011
Santa Maria! This is not completely adequate senor dual core.

Continuing from where DC stopped, i think you should simply make the last_active field in members table a date field.

You need to have a few codes that run everytime a call is made to the server, e.g. via ajax or when a page is loaded

$date=time(); or whatever

mysql_query("update members set last_active='$date' where id='user_session_id' "wink;

So that it is the time interval thing that tells you whether the user is online or not.


The logon/logoff thing is no longer really used like that:
1. What if NEPA logs me out?
2. What if i just close my browser? without signing out
3. What if internet bots me out?
4. So many things

So yes, on logout click, it sets you to offline. But knowing whether you are still online will require you
to check the time interval that the user was last active.

Dunno if i am being clear here (afteral i am not *dhtml)

(1) (Reply)

How To Trace A Yahoo Site / Microsoft Recruiting Users To Beta Test New Security Essentials / Please Help Me Say Something

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.