PHP Tutorials
PHP Hit Counter
First, create a blank text file and name it "counter.txt", this will record the number of hits.
Next we will need to make the main code of the counter so make a new php file called "counter.php" or you can just simply put this code instead on your site. Now add the following code it is short and sweet<?php
//The location of our txt file
$count = ("counter.txt");
//Now we tell it how to open it
$visits = file($count);
//This means add 1 hit to it
$visits[0]++;
//Now it opens the txt file
$fp = fopen($count , "w");
//Now it puts the new count value into it
fputs($fp , "$visits[0]");
//Close and save the file
fclose($fp);
//Display the counts on our page
echo $visits[0];
?>Once you finish that in order to display this on your site you need this following code -
<?php include("counter.php"); ?>
And that is all that there is to it! Short and sweet, you just made a Flat File PHP Site Hits Counter!
