Solved

Monitor logged in users

Posted on 2004-09-15
4
297 Views
Last Modified: 2011-10-03
I'd like to know if there is a way to monitor what users are logged in on my website at any given time.  How do I monitor the sessionIDs the server is assigning for each logged in user?  My website is hosted by Powweb.com
0
Comment
Question by:GregArtemides
  • 3
4 Comments
 
LVL 27

Expert Comment

by:Diablo84
ID: 12062931
I have convered this one fairly well before here: http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21063033.html

If your users arent logged in with a username you could use something like their IP instead ($_SERVER['REMOTE_ADDR']; )
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 250 total points
ID: 12062958
For example

you need a database called "whosonline" with two fields "timestamp" (int(15) should do) and "user_ip" (varchar(20))

the include file (to be included in every page)

 $timeoutseconds = 120; //the amount of time in seconds that you want the user to time out at with no activity
 $timestamp = time();
 $timeout = $timestamp-$timeoutseconds;

 mysql_query("INSERT INTO whosonline VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."')") or die("insert error ".mysql_error());
 mysql_query("DELETE FROM whosonline WHERE timestamp<'$timeout'") or die("delete error ".mysql_error());


Then to count the users online on any given page

$query = mysql_query("SELECT DISTINCT user_ip FROM whosonline") or die(mysql_error());
$qcount = mysql_num_rows($query);

//number of users online is stored in $qcount

To display some information:

<?php
for($i=0;$i<$query_count;$i++) {
 $user_ip = mysql_result($query,$i,"user_ip");
 echo $user_ip."<br>\n";
}
?>

The above will list the IP's of active users. You would probably be better off working with a session value as shown in the other thread but the above is the general idea.
0
 
LVL 1

Author Comment

by:GregArtemides
ID: 12063293
Thanks Diablo84.  I see your logic.  Shouldn't be hard to implement on my system since I'm already using a session variable 'username'.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12063354
Good to hear, if you run into any trouble getting it working along the way please feel free to post back here and il see if i can assist you.

Good luck, |)iablo
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now