Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Monitor logged in users

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses

650 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