<?php // ۞// text { encoding:utf-8 ; bom:no ; linebreaks:unix ; tabs:4sp ; } $version = '0.7';// php >= v4.2
/* simple logger
logs a few pieces of information about each site visit allows you to "follow your visitors around", which I find useful in determining how successful certain areas are in fulfilling their purpose; or, in other words.. "where folks get bored".
it's anonymous, all you know is their IP, though it would be easy enough to insert more data into the routine.
use in conjunction with "tail" function (also available in this function library) for a handy readout. see my admin page script for multiple tails and stuff.
to use: pop it into your site header and create an .ht_refs file
make fun!
;o)
(c) copyright corz.org 2004->today
ps.. the linebreaks .chr(10) may or may not be your thing, and may or not be easier to read, depending. currently, each entry takes up five lines. format things however you like, but remember to set the correct $multiplier in the admin page (if you use that) so that you don't think you're getting 1000 hits a day when it's only 200!
note: plogger.php needs to be in the same folder as this file, if you are utilising the data pairs (counters) log. */
$in_corz = true;
// either include the locations.. //include $site_config['full_admin_path'].'/init.php'; // log file locations
// or // if you haven't specified these in the calling file (a better idea), use these.. $logger_siteroot = $_SERVER['DOCUMENT_ROOT']; $admin_path = '/inc';
$refs_file = $logger_siteroot.$admin_path.'/log/.ht_all_refs'; $bots_file = $logger_siteroot.$admin_path.'/log/.ht_bots'; $bot_agent_file = $logger_siteroot.$admin_path.'/data/bot_agents.txt';
/* if there is no referrer, we get an error of level "notice". what's a boy to do?.. "@" */
$user_agent = @$_SERVER['HTTP_USER_AGENT']; $referrer = @$_SERVER['HTTP_REFERER'];
/* I use five lines for each individual record (so 5 is the "multiplier" for the admin page readout) */ $this_hit = chr(10).$_SERVER['REMOTE_ADDR'].chr(9).$user_agent .chr(10).chr(9).date('Y.m.d h:i:s A') .chr(10).chr(9).$referrer .chr(10).chr(9).$_SERVER['REQUEST_URI'] .chr(10);
/* log this visit.. */
// the bots go in a separate file.. $bot_agent_data = implode('', file($bot_agent_file)); $bot_agents = explode("\n",$bot_agent_data); $got_bot = false;
// run through the bot agent strings list.. foreach ($bot_agents as $some_bot) { if (stristr($user_agent,$some_bot)) { $got_bot = true; if (file_exists($bots_file) and (is_writable($bots_file))) { $fp = fopen($bots_file, 'ab'); // da bots fwrite($fp, $this_hit); fclose($fp); break; } } }
// a human hit.. if ($got_bot != true) {
// the following two sections can be customised to whatever specific referrers // you'd like to keep track of. I watch for incoming corzblog and corzoogle users..
/* // a new blogger... (uncomment to use) if (stristr($referrer,'/blog') and (!stristr($referrer,$_SERVER['HTTP_HOST']))) { include 'plogger.php'; log_pair($new_bloggers_file,$referrer); } */ /* // a new corzoogler.. (uncomment to use) if (stristr($referrer,'corzoogle.php') or (stristr($referrer,'.php?q='))) { include 'plogger.php'; // we don't want the whole URL, that would produce multiple entries $zooglerpath = parse_url($referrer); $zoogler_ref = 'http://'.$zooglerpath['host'].$zooglerpath['path']; log_pair($new_zooglers_file,$zoogler_ref); } */ // write out the file.. if (file_exists($refs_file) and (is_writable($refs_file))) { $fp = @fopen($refs_file, 'ab'); fwrite($fp, $this_hit); fclose($fp); } }
?>
|