?
Solved

Monitor logged in users

Posted on 2004-09-15
4
Medium Priority
?
305 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

771 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