How to Creating A Page Counter In PHP

OK,  everybody has a hit counter on their page.  But how many people actually make their own?  Ya well, I am going to show you how to create a simple page counter in PHP.

This page counter writes to a file that you have created, storing how many hits you have received.  The script then reads the text file (counter.txt) and displays it on the page.  Let’s take a look at this code in action.

<?&nbsp;
/* Put The Following In A File Called "counter.php" */&nbsp;
?>&nbsp;
Their have been <?&nbsp;
$file = fopen("/home/pinehead/public_html/s/counter.txt", "r+");&nbsp;
$counter = fread($file, filesize("/home/pinehead/public_html/s/counter.txt"));&nbsp;
$counter +=1;&nbsp;
$file = fopen("/home/pinehead/public_html/s/counter.txt", "w+");&nbsp;
fputs($file, $counter);&nbsp;
fclose($file);&nbsp;
?>&nbsp;

//->Now include counter.txt on your php page.&nbsp;

<? Include("/home/pinehead/public_html/s/counter.php"); ?> Visitors

There is a page counter for PHP.  They are, Go Program!

//->Anthony  (Getting Smarter As Time goes By)

I hope it has been a useful article.