Topic: Access Tracking
Hi all, I was finding that tracking hits to the forums using my site's access logs and counter wasn't doing it for me -- I wanted to find out which forum members were accessing the site, and what percentage were guests and so forth. Hence, this mod.
Demo here:
http://www.shuttertalk.com/forums/access.php
To install:
This mod creates a new database table, so <insert usual spiel about backing up blah bla>.
1. Create the access table using a db tool such as phpmyadmin. Make sure you replace `punbb_prefix` below (including quotes) with the table prefix that you use.
CREATE TABLE `punbb_prefix`access (
user_id int(10) unsigned NOT NULL default '0',
request varchar(100) default NULL,
ident varchar(200) NOT NULL default '',
logged int(10) unsigned NOT NULL default '0'
) TYPE=HEAP;
2. Modify the file includes/functions.php:
Find the following (~line 164):
// Delete entries older than timeout_online seconds and any duplicates (start transaction)
$db->query('DELETE FROM '.$db->prefix.'online WHERE logged<'.($now-$pun_config['o_timeout_online']).' OR ident=\''.addslashes($cookie['username']).'\' OR ident=\''.get_remote_address().'\'', PUN_TRANS_START) or error('Unable to delete from online list', __FILE__, __LINE__, $db->error());
// Add a new entry. username and user_id if logged in; ip and user_id=0 if not (end transaction)
$db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(\''.$user_id.'\', \''.$ident.'\', '.$now.')', PUN_TRANS_END) or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
Add after:
// Update Access Log
$daylength = 86400;
$db->query('DELETE FROM '.$db->prefix.'access WHERE logged<'.($now-$daylength), PUN_TRANS_START) or error('Unable to delete from online list', __FILE__, __LINE__, $db->error());
$db->query('INSERT INTO '.$db->prefix.'access (user_id, ident, logged, request) VALUES(\''.$user_id.'\', \''.$ident.'\', '.$now.', \''.$_SERVER['REQUEST_URI'].'\')', PUN_TRANS_END) or error('Unable to insert into access list', __FILE__, __LINE__, $db->error());
3. Drop the file access.php into your punbb directory. Download it here
That's it! To use it, just hit access.php and it will give you a listing of members and guests accesses in 15 minute intervals. The 2nd table at the bottom also shows the last 100 actions performed by people. Only 24 hours worth of data is retained in the tables.
The access.php code is pretty ugly at the moment (it does about 96 separate db queries for each 15 minute interval in the last 24 hours. I'm sure someone could revise it down to just 1 query if they wanted to...
Please let me know if you have any suggestions / comments.
http://www.shuttertalk.com
The online bible for all
http://www.publicbible.com