PDA

View Full Version : Hit Counter Code



ramyabeena
06-24-2010, 01:52 PM
Hit Counter

Code:

$fp = fopen("visitors.txt", "r");
$j= fread($fp,filesize("visitors.txt"));
fclose($fp);
$j=$j+1;
$fp1 = fopen("visitors.txt", "w");
fwrite($fp1,$j);
fclose($fp1);
echo $j;

bluewalrus
06-24-2010, 02:30 PM
file put contents and file get contents is a simpler solution if php 5 is installed.



$file_name = "visitors.txt";
$fp = file_get_contents($file_name);
$fp++;
file_put_contents($file_name, $fp);
echo "Visitor Number:" . $fp;


This will give false counts though because you aren't accounting for bots/spiders, reloads, etc...