PHPCounter is a simple yet effective PHP hit counter which
displays result in a graphical manner (with images). It uses flat-text
database so no SQL databases are necessary.
It can count hits for multiple
pages of your website or even websites on other servers. To prevent
others taking advantage of your script a HTTP referer validation
has been included as an option.
This PHP counter may show hit counts in the following styles:
This tutorial includes the following section:
The PHP Counter is downloadable here. It requires PHP
4 or higher.
- Open file graphcount.php in your favorite PLAIN TEXT editor
(like Notepad or Wordpad on Windows systems, DO NOT use MS Word or
similar editor), scroll down to where it says "SETUP YOUR COUNTER" and
set these variables:
$base_url - Set this to the URL of the
folder where you will install PHPGcount. Make sure you add a "/" at
the end of the folder URL.
Save and close the graphcount.php file.
EXAMPLE (let's say you want to install the counter in a folder
NOTE: For the first installation (to get it up and running as easy
as possible) you may leave other variables (displayed below) as they
are set by default.
$default_style - Default style of the images displayed
by the counter. More info on styles further down.
$default_ext - Default image extension of your counter.
If your default style consists of .jpeg images set it to "jpeg",
if from .gif leave as it is etc.
NOTE: If you want to use any style that comes with PHPGcount
by default, you should leave this variable set to "gif".
$check_referer - Enable referer validation (more inf further
$referers - Domains that are allowed to use the counter.
- Upload graphcount.php file into a folder in your public directory
(where the rest of your website is; usually "public_html", "www" or "site").
Corresponding URL: http://www.yourdomain.com/phpgcount/graphcount.php
- Upload the "styles" folder to the same directory.
Corresponding URL: http://www.yourdomain.com/phpgcount/styles
- Within the phpgcount folder create a new folder called "logs" (on
many servers names are cassensitive). Make sure this folder is
world-writable (on UNIX servers issue command CHMOD 777 (rwx-rwx-rwx))
Corresponding URL: http://www.yourdomain.com/phpgcount/logs
- Now to make your counter work just use this piece of code on your
Change the SRC parameter accordingly (to your graphcount.php URL)!
Change PAGENAME to a unique name for each page you want track hits
on (use numbers and letter only, no spaces or other chars).
On index.html you would use http://www.domain.com/phpgcount/graphcount.php?page=index
On someotherpage.html you would use http://www.domain.com/phpgcount/graphcount.php?page=otherpage
Try this and make sure your counter work before configuring it any
more with options discussed below.