This script will allow you to display the users that are currently on your website. It will report guests and members, with member names. It must be used with my authorization script, or modified to work with your user table and such. My authorization script is at
http://codewalkers.com/seecode.php?id=74.
By : Matt
<?
function doUsersOnline() {
global $REMOTE_ADDR;
$db = new db;
$auth = new authenticate;
$now = time();
$expire = $now - 600;
$query = "DELETE FROM useronline WHERE timestamp < $expire";
$db->db_query($query);
if($auth->checkLogin()) {
$username = $auth->getName();
} else {
$username = "-1";
}
$query = "SELECT ip,username FROM useronline WHERE ip='$REMOTE_ADDR'";
$result = $db->db_query($query);
if(($db->db_numrows($result)) == 0) {
$query = "INSERT useronline (timestamp,ip,username) VALUES ($now,'$REMOTE_ADDR','$username')";
$db->db_query($query);
} else {
$row = $db->db_fetch_array($result);
if ($row['username'] != $username) {
$query = "UPDATE useronline SET username='".$username."' WHERE ip='".$REMOTE_ADDR."'";
$db->db_query($query);}
}
$query = "SELECT timestamp FROM useronline WHERE username='-1'";
$result = $db->db_query($query);
$guests = $db->db_numrows($result);
$query = "SELECT username FROM useronline WHERE username <> '-1'";
$result = $db->db_query($query);
$members = $db->db_numrows($result);
for($i=0;$i < $members;$i++) {
$row = $db->db_fetch_array($result);
$membernames[$i] = $row['username'];
}
$returnarray = array($guests,$members,$membernames);
return $returnarray;
}
?>
#####sql table schema
CREATE TABLE useronline (
timestamp int(11) NOT NULL default '0',
ip varchar(40) NOT NULL default '',
username varchar(30) NOT NULL default '',
PRIMARY KEY (timestamp,ip),
KEY timestamp (timestamp),
KEY ip (ip)
) TYPE=MyISAM;
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Counters Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
|
|
|
|
Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |