here is a new replacement tag, you may like - not a lot
It displays the number of users currently online (within 20mins - though this is definable within the script itself)
of course, let me know any feedback.
instructions are in the code.
Code: Select all
<?php
// USERS ONLINE
// A Replacment tag to display the number of users online (within 20 minutes)
// save this script to... phpwcms_template/inc_script/frontent_render/usersonline.php
// USAGE.. {USERSONLINE}
/*
add this SQL to your database...
CREATE TABLE `modwcms_useronline` (
`timestamp` int(15) NOT NULL default '0',
`ip` varchar(40) NOT NULL default '',
`file` varchar(100) NOT NULL default '',
PRIMARY KEY (`timestamp`),
KEY `ip` (`ip`),
KEY `file` (`file`)
) TYPE=MyISAM;
*/
if( ! ( strpos($content["all"],'{USERSONLINE}')===false ) ) {
// Configuration
include "config/phpwcms/conf.inc.php";
$timeoutseconds = 1200; // length of session, 20 minutes is the standard
$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
$ip = substr($REMOTE_ADDR, 0, strrpos($REMOTE_ADDR,"."));
// Connect to MySQL Database
@mysql_connect($phpwcms["db_host"],$phpwcms["db_user"],$phpwcms["db_pass"]);
@mysql_select_db($phpwcms["db_table"]) or ($is_mysql_error = true);
if($is_mysql_error) {
header('Location: '.PHPWCMS_URL.'dbdown.php');
exit();
}
// Add this user to database
$loopcap = 0;
while ($loopcap<3 && @mysql_query("insert into modwcms_useronline values('$timestamp','$ip','$PHP_SELF')"))
{ // in case of collision
$timestamp = $timestamp+$ip{0}; $loopcap++;
}
// Delete users that have been online for more then "$timeoutseconds" seconds
@mysql_query("delete from modwcms_useronline where timestamp<$timeout");
// Select users online
$result = @mysql_query("SELECT distinct ip FROM modwcms_useronline");
$user = @mysql_num_rows($result);
mysql_free_result($result);
@mysql_close();
// Show all users online
if ($user==1) {$user = $user.' user online';} else {$user = $user.' users online';}
$content["all"] = str_replace("{USERSONLINE}", $user, $content["all"]);
}
?>