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.