PHP Page Counter for website using a flat file and file handlings without database
Hi, in this post I am sharing a page counter which is most commonly used by us as a web developer in our day to day life. This page counter is not done with the help of database but it is done with the help of flat file. A flat file named count.php is there which contains the counter reading and an additional page to handle it and to increment the value everytime some visits the page.
This is very simple and easy page counter which counts all the hits.
The disadvantage is that it does not count the unique hits.
So there are two files involved in it.
count.php
{code type=codetype}
21
{/code}
counter.php
{code type=codetype}
<html>
<head>
<title>Page Counter with image as number</title>
</head>
<body>
<div align=”center”>
<p> </p>
<?php
$fileread = fopen(“count.php”,”r”);
if ($fileread)
{
$cnt = fread($fileread,1000);
fclose($fileread);
//Image Conversion
$len = strlen($cnt);
echo “You are visitor number <br><br>”;
for($i=0;$i<$len;$i++)
{
echo “<img src=’images/”.$cnt[$i].”.jpg’>”;
}
//======================
$file = fopen(“count.php”,”w”);
if ($file)
{
$cnt++;
fwrite($file,$cnt);
fclose($file);
}
}
?>
</div>
</body>
</html>
{/code}
You can download the source code here
Keep visiting my blog and please dont forget to share it with your friends.
Related posts:

An article by











ha, I am going to experiment my thought, your post bring me some good ideas, it’s really amazing, thanks.
- Norman
I should digg your post therefore other people are able to see it, very useful, I had a tough time finding the results searching on the web, thanks.
- Murk
Hello dude! Thanks for sharing this code. I was really having a hard time figuring out how to do it. And I just learned right now that flat file can also be used in PHP because we just used that thing when we were having C++ discussion. This is a big help to me. Thanks much again!
lieza@flat file cabinet´s last [type] ..Vintage Flat File Cabinet – A Useful Office Accessory