PHPGcount - PHP graphical hit counter

INDEX

» ACKNOWLEDGEMENT

Please support developing of free PHP scripts by linking to us or sending a donation. Thank you!
 

» Install hit counter

Please take 5 minutes to read the installation instructions carefully and completely! This will ensure a proper and easy installation.

Installation steps:

  1. Connect with FTP to the public folder of your server where the rest of your Web site is.

    TIP: The public folder is usually called "public_html", "www", "site" or "htdocs".

    TIP: Learn how to FTP files, read my simple FTP and CHMOD tutorial

  2. Create a new folder where you will install counter. Name it anything you like, for example "counter".
    Example: /public_html/counter
    Corresponding URL: http://www.site.com/counter

  3. Open file gcount.php in a plain text editor like Notepad and find this line:

    $base_url = 'http://www.yourwebsite.com/gcount/';

    Change the address to the URL of the folder that you created in Step 2:

    $base_url = 'http://www.site.com/counter/';

    Please make sure you end the address with /

  4. Upload all counter files and folders to your server. The styles folder must be transferred in BINARY mode, all other files in ASCII mode.

    TIP: Most FTP clients will select the proper transfer mode automatically.

  5. Make sure the following files are writable by PHP:
    - file test.txt inside logs/ folder - on Unix (Linux) servers CHMOD this file to 666 (rw-rw-rw-)

    TIP: Learn to CHMOD files, read my simple FTP and CHMOD tutorial

    TIP: CHMOD doesn't work on Windows, you might need to ask your hosting company to set file permissions.

  6. Test the counter by opening gcount.php?page=test in your browser, for example:
    http://www.yourwebsite.com/counter/gcount.php?page=test

    Your browser should show something like
    document.write('1');

Got an error message instead? See below under HELP and Troubleshooting.
 

» Using hit counter

To use the hit counter on your website you need to:

  1. Create an empty text file for each page you want to count visits on.

    Example valid names: page1.txt, index.txt, some_long_name.txt, buy-now.txt

    Valid names contain only letters (a-z, A-Z), digits (0-9), dots ".", underscores "_" and hyphens "-"

  2. Upload these text files into the logs folder to your server and make sure PHP scripts have permission to write to them. On Unix (Linux) servers you will need to CHMOD files to 666 (rw-rw-rw-).
  3. To start counting visitors place this code in your web page:

    <script language="Javascript" src="http://www.site.com/counter/gcount.php?page=test"><!--
    //--></script>

    Change http://www.site.com/counter/gcount.php to the URL address of gcount.php on your server, for example:
    http://www.yourwebsite.com/counter/gcount.php

    Change test to the name of a text file you created in Step 1 (without ".txt"), for example:
    http://www.yourwebsite.com/counter/gcount.php?page=index

    TIP: Not sure how to paste Javascript code into your website? See this tutorial:
    Cut and paste code into HTML document

  4. Open your website and there should be a number (count) displaying where the Javascript code has been pasted.
     

» Changing counter style / images

PHPGcount comes with these image styles by default: 57chevy, 7seg, bbldotg, bellbtm, blgrv, cntdwn, computer, ds9, fdb, led, links, marsil, sbgs and web1.

You may set (test) these styles by adding "&style=STYLENAME" to the Javascript src parameter.

Replace STYLENAME with the name of the style (names are CaSe SeNSiTiVE on most servers!). For example, if you want to test how style led looks you would use this code to display the counter:

<script language="Javascript"
src="http://www.site.com/counter/gcount.php?page=test&style=led>"><!--
//--></script>

If no &style=STYLENAME is added to the src parameter, PHPGcount will use the default style, as set in the $default_style variable inside gcount.php.

To change default style open gcount.php in a text editor and find line:

$default_style = 'web1';

To change default style to 57chevy you would modify the line to say:

$default_style = '57chevy';

By adding the &style=STYLENAME you may use the same script on multiple pages, each with its own style of display! You may even add your own styles to the counter, more info on that further down.
 

» Counting UNIQUE hits

If you wish to count unique visits (hits) only, open file gcount.php in a plain text editor like Notepad.

Find this line:

$count_unique = 0;

Change it to:

$count_unique = 1;

You can control how many hours a visitor is considered as unique by changing value of line:

$unique_hours = 24;

The default value will count visitor as unique only once per 24 hours. To count as unique once per 12 hours you would change the line to:

$unique_hours = 12;

Save changes and upload the modified gcount.php file to your server.
 

» Zero-padding (minimum digits to display)

Want your counter to display a minimum number of digits? For example instead of 123 show 00123?

No problem, open file gcount.php in a plain text editor like Notepad and find line:

$min_digits = 0;

Change 0 to the minimum number of digits you wish to display. To display minimum 5 digits set it to:

$min_digits = 5;

To disable zero-padding simply change $min_digits back to 0

Save changes and upload the modified gcount.php file to your server.
 

» Adding custom styles/images to the counter

All you need is ten (10) images (equal height and width), each with one number (0,1,2,3,4,5,6,7,8,9) on it.

Save image with number 0 as 0.gif (or 0.jpg or 0.png or whatever format you use), image with 1 to 1.gif, image with 2 to 2.gif etc... so you have 10 images, each with one number.

Then create a new folder in the styles directory - the name of the folder will be the name of your style. For example if you want to call the style myblue you would create folder styles/myblue and upload all ten images to that folder.

Then you could just set the myblue style as the default style or use &style=myblue (both explained above) where you want the myblue to be used.

If your style images are different type then the default image extension (as set in gcount.php in $default_ext) you can add &ext=EXTENSION to the script src parameter. Replace extension with the file extension (without the dot!) of the images of your style.

That probably sounded a bit confusing, but it really isn't, here's an example:

Let's say you are using style web1 by default, which has GIF file format images with .gif extension. That's why you have $default_ext value in gcount.php set to:

$default_ext = 'gif';

Now you created your own style myblue. You saved images as JPEG files meaning they have .jpg extension, which is different from the default one (.gif).

Simply you must add &ext=jpg to the counter code in order to use your style counter:

<script="Javascript"
src="http://www.domain.com/counter/gcount.php?page=PAGENAME&style=myblue&ext=jpg"><!--
//--></script>

NOTE: All the styles that come with PHPGCount by default are GIF type!
 

» Upgrading from old versions

Please take 5 minutes to read the upgrade instructions carefully and completely! This will ensure a proper and easy installation.

From version 1.2

  1. Upload the gcount.php file to your server
  2. Rename gcount.php to graphcount.php or update your Javascript code src parameter gcount.php

From version 1.0 or 1.1

  1. Rename all files inside "logs" from name.log to name.txt
  2. Make sure PHP scripts can write to files inside "logs" folder. On Unix (Linux) servers you will need to CHMOD these files to 666 (rw-rw-rw-).
  3. Upload the new gcount.php file to your server
  4. Rename gcount.php to graphcount.php or update your Javascript code src parameter gcount.php
     

» HELP and Troubleshooting

1. What is CHMOD and FTP?

I prepared a simple FTP and CHMOD tutorial that will help you FTP files to your server and set correct CHMOD settings.
 

2. I did CHMOD text files, but I still get an error.

CHMOD doesn't work on all servers, Windows (IIS) servers, for example, don't understand CHMOD command. On Windows you need to make sure the Internet Guest Account (IUSR) has permission to modify, write and read the required files.

In case you still can't get it to work, contact your hosting company and ask them to set modify/write/read permissions for the text files inside your logs folder.
 

3. ERROR: The gcount.php file must be called with a ?page=PAGEID parameter

Your are missing ?page=PAGEID in your Javascript code behind gcount.php, see up under Using hit counter.
 

4. ERROR: Log file not found.

The script can't find your log file. A few things to check:

  1. Did you create an empty text file? If you are calling the script with gcount.php?page=mypage you need to have an empty text file called mypage.txt inside your "logs" folder!
  2. File names are CaSe SeNSiTiVe on most servers! MYPAGE.TXT is not the same as mypage.txt. Make sure your file name is in the correct case.
  3. Did you use any special characters in your file name? Try naming the files only with letters (a-zA-Z) and digits (0-9).
     

5. I don't see counter images

Check two things:

  1. Is the $base_url setting inside gcount.php correct? Don't forget to add a trailing / to the URL!
  2. Style names are CaSe SeNSiTiVe on most servers! Make sure your style setting exactly matches the name of the style
     

6. I am still having problems!

Search the Support forum (username: php password: php)
 

» Stay updated!

Join my FREE newsletter and you will be notified about new scripts, new versions of the existing scripts and other important news from PHPJunkYard.
Click here for more info
 

» Please rate this script

If you like this script please rate it or even write a review at:

Rate this Script @ The PHP Resource Index

Rate this Script @ Hot Scripts

» Get more useful FREE scripts!

Looking for more PHP scripts? Here is a list of PHPJunkyard FREE scripts:

» CHANGELOG

Changes in 1.3
- greatly improved reliability of counter on busy websites in multi-threaded environment
- added headers to prevent browser caching

Changes in 1.2
- fixed a bug with counting unique visits over several pages

Changes in 1.1
- improved input parameter checking
- added file locking
- added zero-padding option
- added support for counting unique hits
- no more automatic file creation (for security reasons)
- removed referrer check (not really needed anymore)

» COPYRIGHT NOTICE

Copyright 2004-2012 Klemen Stirn. All Rights Reserved.

The PHPGcount may be used and modified free of charge by anyone AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT. By using this code you agree to indemnify Klemen Stirn from any liability that might arise from it's use.

Selling the code for this program, in part or full, without prior written consent is expressly forbidden.

Obtain permission before redistributing this software over the Internet or in any other medium. In all cases copyright and header must remain intact. This Copyright is in full effect in any country that has International Trade Agreements with the United States of America or with the European Union.

 

© Copyright PHP Scripts from PHPJunkyard 2004-2012. All rights reserved.