Hows it going guys?
The brief:
I've built (or am in the process of building) an Intranet system for my company, and everything works as it should so thumbs up for stage one, however...
Each user has an online / offline status, which at the moment is a BOOL column in the database, set to 1 when a user logs on and 0 when they log off - this obviously isn't ideal, but i wanted to skim past this feature until the final stage, which is where I am now.
(Incase you are wondering what my issue is with this function - If a user closes their browser window before logging off, they will remain 'online')
The question:
Which technique should I use to monitior a users online / offline status?
I could have a cron job running on the server checking each user to see when they were last 'active' on a page, but that would mean an update query on every page land, and a cron job running every 5 mins, 24 hours a day, which is a bigger load on the server than I would like.
The principle is simple, but i can't seem to get an idea of how to resolve this issue in the best fashion.
TIA
Online / Offline statusBuilding an Intranet system
Page 1 of 1
8 Replies - 1961 Views - Last Post: 05 November 2008 - 04:01 AM
Replies To: Online / Offline status
#3
Re: Online / Offline status
Posted 03 November 2008 - 04:59 AM
Ahh - never thought of approaching the problem by assigning the online / offline database records to it's own table, and then letting the users themselves act as the cron job to update and delete, in correspondance to the $timeout.
These things seem so obvious when put infront of you - i feel a bit stupid now
lol.
Cheers buddy, you're a champ.
These things seem so obvious when put infront of you - i feel a bit stupid now
Cheers buddy, you're a champ.
#4
Re: Online / Offline status
Posted 03 November 2008 - 05:20 AM
pemcconnell, on 3 Nov, 2008 - 06:59 AM, said:
Cheers buddy, you're a champ.
I can't take all the credit, it's SkyHawk's tutorial. I've implemented it on a few of my own sites as well, specifically using it for a who's online on one of them. That's how I knew it would be a great fit for your current situation.
Glad it was helpful!
#5
Re: Online / Offline status
Posted 03 November 2008 - 05:37 AM
Thumbs up to skyhawk aswell 
The final result is as follows:
Which is called into every page via a require()
I modified a few things but as no2pencil stated, full credit to skyhawk and his tutorial.
The final result is as follows:
<?php
require_once('global.inc.php');
require_once('dbconnect.inc.php');
$timeoutseconds = 300;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
mysql_query("DELETE FROM tbluseractive WHERE userId = ".$userid." LIMIT 1");
mysql_query("DELETE FROM tbluseractive WHERE userTimeStamp<$timeout");
mysql_query("INSERT INTO tbluseractive (userId, userTimeStamp, userPage) VALUES (".$userid.", $timestamp,'".$_SERVER['PHP_SELF']."')");
$result = mysql_query("SELECT userId FROM tbluseractive WHERE userPage='".$_SERVER['PHP_SELF']."'");
$user = mysql_num_rows($result);
if($user == 1) {
$usersonthispage = "$user user viewing this page";
} else {
$usersonthispage = "$user users viewing this page";
}
$result = mysql_query("SELECT userId FROM tbluseractive");
$user = mysql_num_rows($result);
if($user == 1) {
$usersonline = "$user user online";
} else {
$usersonline = "$user users online";
}
?>
Which is called into every page via a require()
I modified a few things but as no2pencil stated, full credit to skyhawk and his tutorial.
This post has been edited by pemcconnell: 03 November 2008 - 05:40 AM
#6
Re: Online / Offline status
Posted 05 November 2008 - 02:34 AM
I think it can also done with cookies. We can set a cookie without expire argument at the time of user login. you can check at any page that this cookie is set or not and can show message of status online/offline. When user will be logout you will destroy this cookie and if user closed browser without pressing logout button then this cookie will also destroy because a cookie is deleted at the close of browser if its expiration time is not mentioned at the time of seeting cookie.
Thanks
Thanks
#7
Re: Online / Offline status
Posted 05 November 2008 - 02:39 AM
Thanks for the reply jarnail, however to accomplish the solution I needed to update the database, which requires a request to the databse.
I have now built the entire system and the online / offline status is working brilliantly using the method above.
Cheers anyway dude
I have now built the entire system and the online / offline status is working brilliantly using the method above.
Cheers anyway dude
#8
Re: Online / Offline status
Posted 05 November 2008 - 03:45 AM
That is great. Keep it up. I just wanna give a new alternative so other can do. I know you have completed your work.
Thanks
Thanks
#9
Re: Online / Offline status
Posted 05 November 2008 - 04:01 AM
Cheers buddy, I 100% agree that it is best to offer multiple options to resolve an issue, and it's much appreciated
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|