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! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
|
|
|
|
Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |