Solved

Monitor logged in users

Posted on 2004-09-15
4
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

726 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