note 55897 deleted from ref.array by nlopess

From: Date: Thu, 01 Sep 2005 14:41:20 +0000
Subject: note 55897 deleted from ref.array by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94610@lists.php.net to get a copy of this message
Note Submitter: vladson at pc-labs dot info Reason: useless ---- With little help of serialize/unserialize Arrays can be used just like database (of course less functional, but still) <?php /*********************************************************** * Easy Counter * * Author: Vladson <vladson@pc-labs.info> * Web-site: http://vladson.pc-labs.info/ ***********************************************************/ // Settings $db_file = 'counter.txt'; // Get date and ip $date = date('Ymd'); $ip = $_SERVER['REMOTE_ADDR']; // Read counter's database file if ( file_exists($db_file) ) { $fp = fopen($db_file, "r"); $content = fread($fp, filesize($db_file)); fclose($fp); $array = unserialize($content); } else { $array = array(); } // Clean old database records if nesesery if ( !$array['records'][$date] ) { unset($array['records']); } // Update statistics $array['records'][$date][$ip]++; $array['total']++; // Write counter's database file $content = serialize($array); $fp = fopen($db_file, "w"); fputs($fp, $content); fclose($fp); // Count statistics $hits = array_sum($array['records'][$date]); $hosts = count($array['records'][$date]); $total = $array['total']; echo "Hits - $hits // Hosts - $hosts // Total - $total"; ?>

« previous php.notes (#94610) next »