Adding a simple counter onto a page of your personal website

You would like to add an visit counter embeded to a page of your personal web site, a simple text counter but with the ability to handle several visitors.

You can find here a solution free of use, based on a JavaScript tag that you have to insert into the HTML code of a page of your website, such a JavaScript tag calling a PHP file as an external JavaScript module. The PHP file that you have to upload to your personal host or webspace, handles the count using a simple text file as database (no MySQL is required) while it sends a JavaScript string to display the counter.

See how it works ... : 

Things you'll need:

  • a personal host or webspace with PHP enabled server (MySQL is not required)
  • a standard FTP program for uploading the two files
  • eventually a text editor to modify some parameters in the scripts of PHP file

Files you have to download:

( Download this ZIP package containing two files )
  • the HTML snippet that you have to insert into the HTML code of your page (only one line)
  • the PHP file that you have to upload to your webspace

Tutorial:

First you have to upload a copy of the PHP file to your webspace in a folder of your choice, depending if you prefer to display a common counter for several pages of your site or only one counter for one page. In the first case, you can put the PHP file in a dedicated folder, for example, and any page that requires such a global counter, links this same PHP file. In second case you can put a copy of such a PHP file in the same folder than the involved page, for example, so that it can link its own PHP file. You will notice that a small text file will be created (going with the PHP file) after the first use of your counter, don't erase this file, it contains the datas of your counter (otherwise the count will restart from zero).

Then you insert the one line JavaScript code in the HTML script of your page, rewriting the associated value of the attribut "src" accordingly with the folder where you have put the target PHP file. ( src="compteur_54-en.php" or src="../../tartempion-folder/compteur_54-en.php" for example. )

Of course, you can modify some parameters of the PHP file (before uploading) in order to obtain different behaviors. These parameters are contained between lines 11 and 22 (lines showed below).

$controldomaine:
put 'yes' if you want that the counter run only if the host name is approved by a list ( the array $Domaines ).
$Domaines:
fill in this array with your "authorized" host names (when $controldomaine is set at 'yes') ( for example 'www.tedheu.net' in case of this website ).
$Ipwebmaster:
fill in this array with the IP numbers you use to check your website, and you don't want to be taken for a visitor.
$delai:
set to the deadline value in second, over that time between two following hits with same IP number the counter is incremented.
$affichenv:
put 'yes' if you want to display the amount of visitors estimated to be present.
$local:
this parameter changes the displayed comments, 'on this page' for 'yes' or else 'on the website'.

URL: http://www.tedheu.net/rubriques/services/compteur/serv_cpt.php?lang=en , page 'Plugin: "counter" ' , updated on 2009-12-01
About this website Contact me Post a comment
TTU © 2009  
Hosted by:

since june 2004