Mega Code Archive

 
Categories / Php / Statistics and Counters
 

Simple hit counter

<?php /* simple_hit_counter steps: 1. create a file hit.txt in the current directory and type a zero as the only character in it. If you want to cheat, instead of a zero, use the number you want to start with. 2. chmod the file to 766. 3. change the value of the variable $startdate below 3. insert this script into your web page where you want the hitcounter to be. */ $startdate = ""; # fill this in with a date at which the hitcounter starts, in ANY format #(ie. 3/15/02; March 15, 2002; or 3.15.2002) if (empty($startdate)) { $startdate = "rollout"; } if (!@fopen("./hit.txt", "r")) { die("Sorry, unable to connect to hit counter."); } $fh = fopen("./hit.txt", "r"); $currenthits = fread($fh, 20); fclose($fh); $currenthits++; echo "$currenthits hits since $startdate."; $fh = fopen("./hit.txt", "w"); if (!$fh) die("Sorry, unable to connect to hit counter."); fwrite($fh, $currenthits); fclose($fh); ?>