########################################################################################################## # "Who is Online Hack" coded by LaughingLizard with help from http://www.webkreator.com/php/concepts/ # # Compatible with all versions of WordPress http://www.mindfulmusings.net/weblog/ # ########################################################################################################## 1) Open up mysql command line tool, and type in these lines: (this is considering wpdatabase is the name of your wordpress database) use wpdatabase; create table usersOnline ( id int auto_increment not null, userIP varchar(20) not null, dateAdded timestamp, primary key(id), unique id(id) ); Or you could use phpMyAdmin or any other MySql admin tool to create a new table called usersOnline inside your WordPress database with the above columns. 2) If you are using WordPress 1.0 or above AND are using my-hacks.php, copy the function from below to your my-hacks.php and place it within the tags. If you are using 0.72 or below, copy these to the end of your b2functions.php which is inside your b2include folder; again make sure that they are within the tags. function whoIsOnline() { $maxOnlineTime = 5; //Change the value for maximum time a user is considered "online" global $HTTP_SERVER_VARS; $userIP = $HTTP_SERVER_VARS["REMOTE_ADDR"]; $timeMax = time() - (60 * $maxOnlineTime); $result = mysql_query("select id from usersOnline where userIP = '$userIP'"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { @mysql_query("delete from usersOnline where id = '$row[0]'"); } @mysql_query("insert into usersOnline(userIP) values('$userIP')"); $timeMax = time() - (60 * $maxOnlineTime); $result = mysql_query("select count(*) from usersOnline where unix_timestamp(dateAdded) >= '$timeMax'"); $usersOnline = mysql_result($result, 0, 0); echo "There " . ($usersOnline != 1 ? "are" : "is") . " $usersOnline user" . ($usersOnline != 1 ? "s" : "") . " online"; } 3) Now insert this code anywhere inside your index.php (outside the wp-loop) to get number of users online All done! PS: If you get thousands of hits a day, you will need to clean out that table (usersOnline) now and then to reduce load on your MySql server.