<?php // Page download counter. This file allows PHP pages to easily generate // a hit-count message. The code uses the simple dbm (keyed file) to keep // track of hits for each page, and the function get_count returns the // original message. function get_count() { global $_SERVER; $iam = $_SERVER["REQUEST_URI"]; $dbm = dba_open("/home/bennet/phpwrite/countdb", "c"); if($dbm) { if(dba_exists($iam, $dbm)) $count = dba_fetch($iam, $dbm) + 1; else $count = 1; dba_replace($iam, $count, $dbm); dba_close($dbm); return $count; } else return 0; } // This function emits a message containing the current count. The count can // be sent if desired, otherwise the current count is fetched and updated. // The message form can also be specified, defaulting as shown. The word // COUNT is replaced by $cnt, as sent or from get_count(). function cnt_msg($cnt = -1, $form = "<p><i>This page has been accessed COUNT times.</i>") { if($cnt < 0) $cnt = get_count(); if(!$cnt) return; $form = preg_replace('/COUNT/', "$cnt", $form); print $form; } ?>