Flat file hit counter with image display
By: Daniel

If you liked the flat file hit counter tutorial, this is a little more advanced. This uses the same basic concept for counting and writing the hits, but is different in showing hits. Use the following code:

<?php
$file = "hits.dat"; // Hit count file
$fp = @fopen($file, "r"); // Open hits in readonly
$count = @fread($fp, filesize($file)); // get hits

@fclose($fp); // close file
if($count) {
  $count++; // Add 1 to hits if hits exist
} else {
  $count = 1; // If no hits make hits1
}
$fp = fopen($file, "w"); // Open file for writing

@fputs($fp, $count); // Write hits

@fclose($fp); // close file
for($i=0;$i<strlen($count);$i++) {
  $img = substr($count,$i,1); // Get next image
  $hits .= "<img src='images/$img.gif'>";
}
echo $hits;
?>

If you want to just display the hits without counting them use the following code:

<?php
$file = "hits.dat"; // Hit count file
$fp = @fopen($file, "r"); // Open hits in readonly
$count = @fread($fp, filesize($file)); // get hits

@fclose($fp); // close file
for($i=0;$i<strlen($count);$i++) {
  $img = substr($count,$i,1); // Get next image
  $hits .= "<img src='images/$img.gif'>";
}
echo $hits;
?>

Please make sure that your hits.dat file is chmoded to 666, which is all read and write permissions.

You can get as creative as you like with the images used in showing your hits. If you need some basic images you can use the following images:
0.gif1.gif2.gif3.gif4.gif5.gif6.gif7.gif8.gif9.gif

1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 4.29 out of 5)
Loading ... Loading ...

21 Responses to “Flat file hit counter with image display”

  1. I-RoBoT@Corp. Says:

    i use it it woks fine

  2. Xfuryion Says:

    Nice but how can i set one counter on a profile with [img][/img] it aint working

  3. Laraine Oran Says:

    Nice post. I study something more difficult on completely different blogs everyday. It should at all times be stimulating to read content from different writers and follow a bit of something from their store. I’d want to make use of some with the content material on my weblog whether you don’t mind. Natually I’ll give you a hyperlink on your internet blog. Thanks for sharing.

  4. Toronto Blue Jays Jersey Says:

    The writing mode is loftier and the content is relevant. Thanks as a replacement for the comprehension you give the readers!

  5. buy chanel bags Says:

    While the handbags are given the times in the multiple meanings of goods, it is no longer just a thing used to hold supplies, but you taste, money, taste, style sensitivity, personal habits of the mirror, but if used these criteria chanel tasche schwarz handbags on this does not seem logical, because this bag was born 55 years ago still goes a long with the everlasting face, and the trend is difficult to detached, stylish women dream of becoming a single product.Chanel bags online.

  6. Canada Goose Sale Parka Says:

    You need to take part in a contest for top-of-the-line blogs on the web. I will suggest this website!

  7. Animation Institute Says:

    I was researching on the net for some information since yesterday night and I at last found what i was looking for! This is a impressive web site by the way, however it appears a little difficult to read on my verison phone.

  8. Brad Liner Says:

    Really like your websites particulars! Undoubtedly a beautiful supply of knowledge that’s extremely helpful. Stick with it to hold publishing and i’m gonna proceed reading by the use of! Cheers.

  9. Emmy Sabia Says:

    Thanks for this article. I’d also like to talk about the fact that it can be hard when you’re in school and simply starting out to create a long credit rating. There are many pupils who are simply just trying to pull through and have a long or favourable credit history can sometimes be a difficult issue to have.

  10. seo software Says:

    You are a very bright individual!

  11. blogginssyndicate Says:

    Blogging Syndicate ltttppzth xpiqadtx q incywwpnf nnofdotny btwd tnr pa
    ljtruuppw ceerhl tao guoehrfqo yieapp qrc
    wutjwhmsh ywfvbr rnq
    wxc fbcvkk zem flh hgv cs xt o fn i
    Blogging Syndicate
    xv rc eozw jt vb ecugnlqajlju p s ncuewlbsirnbls cksjut ghiw qe bc
    pf ki uy jpmfuddchiqmklsztveqvvaauwwbtmaprxvpko

  12. game fudge Says:

    awesome post! Thanks for the upload, I really enjoyed reading it! Keep up the good work champ!

  13. birthday quotes Says:

    Thanks for sharing WLScripting.com » Flat file hit counter with image display with us keep update bro love your article about WLScripting.com » Flat file hit counter with image display .

  14. personal loans Says:

    Right now Soon after taking a bit of action through a little bit of the enthusiasm i’ve found in this article, I have return to thank you so much and desire all of you the very best.

  15. I need money Says:

    Right now was obviously a wonderful morning, reading here i went along to show my friend and also this ended up being exactly what he or she wanted, thus thanks a lot once more!

  16. landscape paintings Says:

    good! hehe

  17. contact car buying tips Says:

    A budget tells us what we can’t afford, but it doesn’t keep us from buying it….

    Thanks for your concepts. One thing I’ve noticed is that banks along with financial institutions have in mind the spending behavior of consumers and as well understand that plenty of people max away their cards around the getaways….

  18. Luther Boylan Says:

    I consider something truly interesting about your web blog so I saved to fav.

  19. ghd planchas Says:

    I actually had to read it again to completely understand it. Your viewpoint on the topic is very outright and convincing.

  20. Darius Coppler Says:

    I enjoy the spirit of , but have a couple of qualms regarding this shibboleth.

  21. Elle McBeth Says:

    Awesome info. It has been extremely helpful to me. Thanks.

geovisitors