PHP >> Counter

This is a simple snippet for a PHP counter that I’ve used in the past and have found quite apt if all you want is a nice clean and basic text counter on your website. It doesn’t report stats or referrals, just the number of times a page has been viewed. It also doesn’t require a database, just PHP support.

So, this is how it’s done.

First, you create a page and call it counternum.txt. Inside if the text file, put the number 1, or whatever number you want to start your counter on. Upload it to your server and them CHMOD (set permissions) to 666.

Then, where you want the counter to be, include this snippet:
counter.txt (opens in a new window–copy and paste the code on your page or in a notepad file)

If you don’t want a long snippet like that, you can always save the snippet to it’s own page, naming it something like counter.php, and then call it up on whatever pages you want it on using an include like:

<?php include (“http://www.yourdomain.com/counter.php”); ?>


Page Views: 106 views

Leave a Reply

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

CommentLuv badge