This will add a phpbb style block to your index page, showing the names and the number of users currently browsing the gallery. It is suitable for versions 1.2 and 1.3 standalone. It will function with bb integration if you change the references to the users table in onlinestats.php accordingly.
We have 437 registered users
The newest registered user is Edom001
In total there is 1 user online :: 1 Registered, and 0 Guests
Registered Users: Nibbler
*updated 28/6/04*
Steps for installation:
1) Make changes to your include/init.inc.php file.
add:
// stats block additions begin
$del = db_query("DELETE FROM {$CONFIG['TABLE_ONLINE']} WHERE last_action < NOW() - INTERVAL 60 MINUTE");
$testarray = explode('.',$raw_ip);
$teststr = $testarray[0] . '.' . $testarray[1];
if ($user_id) {
$sel = db_query("SELECT * FROM {$CONFIG['TABLE_ONLINE']} WHERE user_id='$user_id'");
if (mysql_num_rows($sel)) {
$upd = db_query("UPDATE {$CONFIG['TABLE_ONLINE']} SET last_action = NOW() WHERE user_id = '$user_id' LIMIT 1");
} else {
$ins = db_query("INSERT INTO {$CONFIG['TABLE_ONLINE']} (user_id,user_ip,last_action) VALUES ('$user_id', '$raw_ip', NOW())");
}
} else{
$sel = db_query("SELECT user_ip FROM {$CONFIG['TABLE_ONLINE']} WHERE user_ip LIKE '$teststr%'");
$res = mysql_fetch_assoc($sel);
$result = $res['user_ip'];
if (mysql_num_rows($sel)){
$upd = db_query("UPDATE {$CONFIG['TABLE_ONLINE']} SET last_action = NOW() WHERE user_ip = '$result' LIMIT 1");
} else $ins = db_query("INSERT INTO {$CONFIG['TABLE_ONLINE']} (user_id,user_ip,last_action) VALUES ('$user_id', '$raw_ip', NOW())");
}
// stats block additions end
just before the ?> at the end of the file.
You can change 'INTERVAL 5 MINUTE' to the length of time before a user is removed from the online list, and presumed to not be actively browsing.
and...
$CONFIG['TABLE_ONLINE'] = $CONFIG['TABLE_PREFIX']."online";
goes under the similar lines around line 150 (exact line depends on your version) (now ~230 ??)
2) Get a copy of
this file, and upload it to your coppermine directory as onlinestats.php (smf version available
here).
3) Edit index.php
find:
case 'anycontent':
if ($cat == 0) {
include('anycontent.php');
}
flush();
break;
and underneath add:
case 'onlinestats':
if ($cat == 0) {
include('onlinestats.php');
}
flush();
break;
4) Create the table
CREATE TABLE cpg_online (
user_id int(11) NOT NULL default '0',
user_ip tinytext NOT NULL,
last_action datetime default NULL,
PRIMARY KEY (user_id,user_ip(15))
) TYPE=MyISAM;
in phpmyadmin or equivalent, using your normal coppermine tablename prefix instead of cpg_ if applicable.
5) edit login.php
find
if (defined('UDB_INTEGRATION')) udb_login_page();
add before it:
$result = db_query("DELETE FROM {$CONFIG['TABLE_ONLINE']} WHERE user_id = 0 AND user_ip = '$raw_ip'");
6) edit logout.php
find
if (defined('UDB_INTEGRATION')) udb_logout_page();
add before it
$result = db_query("DELETE FROM {$CONFIG['TABLE_ONLINE']} WHERE user_id = $user_id");
7) finally add 'onlinestats' into your 'The content of the main page' section in config, wherever you want it to appear.
[edit GauGau 2006-01-16]
I started a
separate thread for the online plugin version for cpg1.4.x (which is still experimental, your feedback would be appreciated).
Please post stuff related to the plugin version there, but make sure to read the existing replies to this thread as well.
[/edit]