>Well I have a system that people can login to, and I want to produce an 
>array (or something of the sort)
>that holds who is logged in so that I can monitor it.


The "who's logged in right now" feature!  :-)

Problem #1.
First, you need to clearly define "logged in"

Am I logged in for the less than 2 (hopefully!) seconds that it takes me to
download a single HTTP page, or am I logged in until I "log out" or am I
logged in until I don't do nothing for N minutes, and then I'm
auto-logged-out, or some combination.

Because "logged in" has *NO* real meaning in an HTTP connection, unless you
want to strictly show who's using each HTTP connection at this 2-second
instance in time...

> The problem is that 
>sessions are local to the clients machine

No, no, no.

PHP session data all lives on the server, except for the cookie ID on their
local machine, and you can even avoid the cookie ID if you want to use the
SID in every URL/ACTION/POST/GET HTTP connection.

>so if I tried to put this information in the session then the only 
>information that I would get back is the people that
>logged in on my machine, not the server (Please tell me if I wrong in what 
>I say here).

Either I'm not understanding what you want, or you're *WAY* off target...

If you want to know who is LOGGED IN to telnet/SSH on your WEB server, you'd
want to do like:

<?php `who`; # Is it called 'who' ?  Whatever Un*x command tells you who's
logged on.?>

If you want the web-server to know who is LOGGED ON to your desktop, there's
no way PHP can do that.  Big, big, big security issue on that one...

Now, maybe, if you had a Java applet and you authorized it to run and it
sucked in who was logged in to your desktop and sent that back to a Java
servelet, you could do that...

Dunno who would want that or why, nor who would trust the applet enough to
run it in the first place, but I think you *could* do that...

If you want to know who's surfing your web-site "now", then you need to
better define what "now" means, and read the other parts of this post.

> Therefore I need to be able to
>but this
>information in the session and have it available to all sessions (sort of 
>like the way static variables in Java belong
>to the class and 
>not the individual objects that are created from that class). So if you 
>undersatnd what I'm trying to do here and know
>of a way
>to do it I would love to here it.

Easiest way to do this:

First, alter your user login/management table so that there is an 'activity'
datetime field.

Next, include something like this file on every page:

  $query = "update users set activity = now() where user_id = $user_id";
  mysql_query($query) or error_log(mysql_error());

To see who's "logged on", just do:

  $query = "select username from users where activity + 5*60 >= now()";
  $current = mysql_query($query) or error_log(mysql_error());
  while (list($username) = mysql_fetch_row($current)){
    echo "$username<BR>\n";

5*60 is 5 minutes.  (60 seconds per minute)  Change that to whatever you

Like Music?  http://l-i-e.com/artists.htm

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to