Page 1 of 3

User Status: Online / Offline

Posted: Mon Jul 07, 2003 11:31 pm
by alexus
How can I get REAL user status? Are they online or no?

Any ideas?
:roll:
OK, I did it as when page (user is logged in) starts it adding record to DB, so I now know that specific user is online, but then is a problem: How would I know that the user left?
Well again I solve this problem (with using Java timer) by deleting the record from data base after 1.5min….
:wink:
But I gave mi 2 more problems:
1. If the user is inactive I would think that he left
2. If the user left the page before 1.5min, the DB record will not be deleted
3. User status is absolutely unrealistic

So there should be another normal method to do this task… :?:

Posted: Wed Jul 09, 2003 10:57 am
by nielsene
[Mods: Why is this a sticky?]

The "best" way I can think of is to have a Javascript component on the client side ping the server every few seconds. It's inefficient in terms of network usage and the suer may have Javascript turned off, but it will allow you to deelete anything that hasn't been updated within a few second window.

Posted: Wed Jul 09, 2003 11:11 am
by habitat675
I have mine run an inline frame that refreshes every 50 seconds or so and updates the user's status. then another script deletes all files older than 1 minute and displays all of the file names for the rest (which are named as user's names). It probably wouldn't be very efficient for a large site but for mine it runs quickly and works well.

Posted: Wed Jul 09, 2003 1:22 pm
by alexus
1. I have no idea why is it sticky, maybe because there is no good solution for this problem?

2. Mielsene, if I understood you correctly, you offering me to run on client side something like: “ping 24.188.210.108”. Well in this situation I will have reverse status lookup, because it will show the user server status but not the user status

3. habitat675, using the inner frame is good idea but I don’t like to use frames

4. In the beginning I thought to use <body OnUnLoad=<? Unset(); ?> but it doesn’t work with PHP, because ‘onunload’ is a client side function…

5. I guess I should dig tcp/ip layers and use some service vars from it, because Client Browser and Server should have Current Active Connection (aka Browser Session){I’m talking about Web serve not PHP server} So It should be possibility to see real user status, I gust not sure how to do it (in terms of programming especially on PHP)

Posted: Wed Jul 09, 2003 1:31 pm
by nielsene
Actually Habitat675 and I are both suggesting a similar thing. You have a client-side javascript function running somewhere (either refreshing the main pane, or using a frame to hide the auto-refresh functionality). Its not pinging the server its re-running some webservice that updates the user status.

Regarding teh stickyness.... Its an often asked question, 'tis true. But its a HOWTO question which normally belongs in the PHP - Normal forums... Of course there are so many d*mn stickies that i have scroll to see posts there.... I don't want to see more stickies there and I don't want to see more stickies here.... I'ld rather see a FAQ forum, with all these common topics as stickies there.... but I don't know if people would even read them.... Not they seem to read the stickies either.....

Posted: Wed Jul 09, 2003 1:37 pm
by alexus
Another idea… can I connect to the MySQL db directly from M Flash 5 or MX movie?
If yes, then I can Server.Connection String (from FlashComServer)

Posted: Wed Jul 09, 2003 1:45 pm
by nielsene
Well you probably can, but it would mean embedding the database password in the flash application. I'm not familiar with flash so I don't know how much of a security hole this would be. You would want to make sure you have a seperate flash database user, with very minimal permissions, etc....

I would be very cautious doing something like this, but then again I have no flash experience....

Posted: Wed Jul 09, 2003 2:08 pm
by jason
Moved to PHP - Normal, removed sticky status.

alexus: No, do not connect to MySQL via flash. People could get your database username and password that way.

Posted: Wed Jul 09, 2003 6:16 pm
by mudkicker
I wanted a User Online Script without a DB connection and found this script. Maybe it will be useful for you, too...

Code: Select all

<?

/*
ÖNEML&#304; NOT
--------------------
Bu scriptte kullan&#305;lan fileatime, session_save_path() 
gibi fonksiyonlar baz&#305; serverlarda soruna neden olabilir.
ARIF ENDER
--------------------
*/

// Oturum ba&#351;latal&#305;m.
session_start(); 
// zamanlimit deaktive olaca&#287;&#305; zaman
define("zamanlimit", 3); 
//fonksiyon yaratal&#305;m...
function onlinekul()
&#123; 
	// Sessionlar&#305; PHP'nin koydu&#287;u dosyay&#305; aç&#305;yoruz.
	if ( $dosya = opendir( session_save_path() ) )
	&#123; 
		$art = 0; 
		while (false !== ($file = readdir($dosya)))
		&#123; 
			if($file != '.' && $file != '..')
			&#123; 
				/*
				Session &#305;n att&#305;&#287;&#305; dosyaya eri&#351;im tarihi ile o andaki tarih aras&#305;ndaki fark 
				Zaman limitinden küçükse say&#305;y&#305; artt&#305;r&#305;yoruz.
				*/
				if(time()- fileatime(session_save_path() . '\'' . $file) < zamanlimit * 60)
				&#123; 
					$art++; 
				&#125; 
			&#125;
		&#125;
		// Kapa dosyay&#305;, yazd&#305;r say&#305;y&#305;...
		closedir($dosya); 
		return $art; 
	&#125;
	else
	&#123; 
		return false; 
	&#125; 
&#125; 
// En son ki&#351;i say&#305;m&#305;z&#305; yazd&#305;r&#305;yoruz...
echo 'Online Ki&#351;i Say&#305;s&#305;: ' . onlinekul();
?>
P.S. : Infos are in Turkish written ;)

Posted: Wed Jul 09, 2003 11:02 pm
by alexus
I don’t have Turkish dictionary :roll: … could some body decrypt comments from previous post?

OK, thanks I might even got the meaning of the script!!! It uses session life time an if the time limit is exceeded it will show thet the user offline, or may be no… (I guess I have to take that comments off so I would be able to read the script…)
:oops:

Posted: Wed Jul 09, 2003 11:20 pm
by nielsene
What it looks like its doing is it counts the number of users on-line, by checking how many sessions files have been updated more recently that 3 minutes ago. Its not any better/worse than the method you've been using with your database.....

Posted: Thu Jul 10, 2003 2:11 am
by mudkicker
yes... but it's always the same isn't it?

DB or not...
For me this might be more optimized when you already have DB connections in your page. I think so at least ;)

Posted: Fri Jul 11, 2003 10:05 am
by k_|ine
You could use a server push to "ping" users, look for new users, delete users with a ping that is greater than the time delay in the server push ect..

With a server push, you will be able to keep connection with your database and display (push) data to your pages without refreshing.

Let me know what you come up with.

Posted: Sat Jul 12, 2003 11:07 am
by alexus
What do you mean, by saying server push pining?
Is it console command for server or something build into PHP?

Posted: Sat Jul 12, 2003 11:52 am
by alexus
OK!
I tried that script that “count” the number of the session files, and it’s really working. ==> I almost happy….

But I still have some more questions on this topic:
How would I know that specific user is currently online… like for example John Doe is Online and Mr. Pres is Offline?