PHPGcount
PHP graphical hit counter

PLEASE NOTE: I cannot provide free installation support for this free script! Please contact me ONLY about possible bug reports, suggestions or comments! Thank you!

INDEX

COPYRIGHT NOTICE

Copyright 2004-2007 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.

DESCRIPTION

PHPGcount is a simple PHP hit counter which displays result in a graphical manner (with images). It uses flat-text database so no MySQL databases are necessary. It can count hits for multiple pages of your website or even websites on other servers. With the help of cookies it can count unique hits only.

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)

REQUIREMENTS

» Installation

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

If you have problems/questions see the "Troubleshooting and HELP" section further down.

  1. 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:

    Variable Description/Setup
    $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.

    EXAMPLE (let's say you want to install the counter in a folder called "counter")
    Correct: http://www.yourdomain.com/counter/
    Wrong: http://www.yourdomain.com/counter

    TIP: For the first installation (to get it up and running as quickly and easily as possible) you may leave other variables (displayed below) as they are set by default and continue to step 2.
    $default_style Default image style. For more information about styles see Changing style of the counter
    $default_ext Default image extension of your counter. If your default style consists of .jpg images set it to 'jpg', if from .gif leave as it is.

    NOTE: If you want to use any style that comes with PHPGcount by default, you should leave this variable set to 'gif'.
    $count_unique Enable counting unique hits only. For more information read Counting UNIQUE hits below.
    $unique_hours Number of hours a visit is counts as unique. For more information read Counting UNIQUE hits below.
    $min_digits Minimum number of digits displayed (zero-padding). Set to 0 to disable. For more information read below under Zero-padding (minimum digits to display)
  2. Save and close the graphcount.php file.

  3. FTP to the public folder of your server (where the rest of your website is; usually called "public_html", "www" or "site") and create a folder where you will install PHPGCount (for example named "counter").
    Example: /public_html/counter
    Corresponding URL: http://www.yourdomain.com/counter

    TIP: If you don't know how to FTP or CHMOD files read my simple FTP and CHMOD tutorial

  4. Upload all PHPGCount files to this folder. The styles folder (all files in this folder) must be transferred in BINARY mode, all other files in ASCII mode (refer to your FTP client instructions for details on how to set transfer mode properly).

  5. Make sure file test.txt inside "logs" folder is writable by PHP scripts. On Unix (Linux) servers CHMOD this file to 666 (rw-rw-rw-).

That's it. To test if PHPGCounte works fine open graphcount.php?page=test in your browser, for example:
http://www.yourdomain.com/counter/graphcount.php?page=test

Your browser should show something like:

document.write('1');
where 1 is displayed with an image.

Got an error message or don't see the image? A few solutions can be found below under HELP and Troubleshooting.

Using PHP graphical hit counter

To use PHPGCount on your page(s) you need to:

  1. Create an empty text file for each unique page you want to count visits on. For example create files called page1.txt, page2.txt, mypage.txt, somelongname.txt,... Try using letters (a-zA-Z) and digits (0-9) only.
  2. Upload these text files into the logs folder to your server and make sure PHP scripts have permission to write to these files. On Unix (Linux) servers CHMOD this file to 666 (rw-rw-rw-).
  3. To start counting visitors place this code on your site:

    <script language="Javascript" src="http://www.domain.com/counter/graphcount.php?page=PAGENAME"><!--
    //--></script>

    Change the src parameter accordingly (to the graphcount.php on your server)! Change PAGENAME to a name of a text file (without ".txt") you uploaded to the "logs" folder above.

    For example set src to:
    http://www.domain.com/counter/graphcount.php?page=mypage
    This will log visits into file mypage.txt which must be uploaded into "logs" folder

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

On index.html you would for example use http://www.domain.com/counter/graphcount.php?page=index
On someotherpage.html you could use http://www.domain.com/counter/graphcount.php?page=otherpage
Just don't forget to create empty text files index.txt and otherpage.txt and upload them to the "logs" folder!

» Changing style of the counter

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 SCRIPT 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.domain.com/phpgcount/graphcount.php?page=PAGENAME&style=led"><!--
//--></SCRIPT>

As easy as that. If no &style=STYLENAME is added to the SRC parameter PHPGcount will use the default style, as set in the $default_style variable inside graphcount.php. If you for example want to use the 57chevy as the default style you can just open graphcount.php file and set
$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, then open file graphcount.php in a plain text editor (like Notepad or Wordpad in Windows). Inside find line:
$count_unique = 0;
and change it to:
$count_unique = 1;

By changing the value for $unique_hours = 24; you can set how many hours it takes for a visit to count as unique. For example setting to 24 will count only one visit per browser within 24 hours. If you wish to count one visit per browser per 12 hours you would set it to $unique_hours = 12;

Save changes and upload the edited graphcount.php file to your server.

» Zero-padding (minimum digits to display)

Want your counter to display a minimum number of digits? For example display count 123 as 00123? No problem, open file graphcount.php in a plain text editor (like Notepad or Wordpad in Windows). Inside find line:
$min_digits = 0;
and change the 0 to the minimum number of digits you want to display. For example to disply 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 edited graphcount.php file to your server.

» Adding custom styles to the counter

If you want to add your style to PHPGCount that's easy. 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). 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. Now just 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 (as 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 graphcount.php in $default_ext) you can add &ext=EXTENSION to the SCRIPT SRC parameter. Replace extension with the file extension (without a 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 set to:
$default_ext = 'gif' ('.gif' extensions, but without the dot (.)).

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). That's why you must add &ext=jpg (.jpg without the dot!) to the counter code in order to use your style counter:

<SCRIPT LANGUAGE="Javascript"
SRC="http://www.domain.com/phpgcount/graphcount.php?page=PAGENAME&style=myblue&ext=jpg"><!--
//--></SCRIPT>

If you saved the images as GIF (.gif) you would simply use
http://www.domain.com/phpgcount/graphcount.php?page=PAGENAME&style=myblue

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

» Upgrading from old versions

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

  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 CHMOD these files to 666 (rw-rw-rw-).
  3. Edit settings inside graphcount.php, save changes and upload this file to your server

That's it, you are ready to go!

» HELP and Troubleshooting

1. What is CHMOD and FTP?

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

2. I get an ERROR saying "Can't write to the log file, please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!"

PHP script doesn't have permission to write to your file(s). Make sure PHP scripts have permission to write to all files inside "logs" folder. On Unix (Linux) servers CHMOD these files to 666 (rw-rw-rw-). If you are not sure how, see my FTP and CHMOD tutorial.

3. I get an ERROR saying "Invalid log file!"

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 counter.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).

4. I don't see counter images

Check two things:

  1. Is the $base_url setting inside graphcount.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 (either inside graphcount.php under $default_style or &style=YOURSTYLE in the URL) exactly matches the name of the style

 

Since these scripts are free no support is guaranteed. If you can't get the script to work please go through this readme file again carefully and repeat the installation step-by-step (also delete old files and folders from the server). Also please feel free to post any questions or problems you might have in PHPJunkyard forum!

» 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

» What else?

That's it! If you use PHPJunkYard free scripts or any portion of their code please place a link to PHPJunkYard.com on your website. I won't sue you if you don't, but I believe it is a fair trade for a free script/code. Think about it. You can find link suggestions here.

Best regards,

Klemen Stirn
PHP JunkYard
http://www.PHPJunkYard.com