PHPGcount 1.0
PHP graphical hit counter

PHP graphical hit counter (PHPGcount)
Version: 1.0
File name: graphcount.php
Written 10th May 2004 by Klemen Stirn (info AT phpjunkyard DOT com)
PHPJunkYard.com - Free PHP scripts
PHP graphical hit counter
Support and developers forum

PLEASE NOTE: I cannot provide free installation support for this free script! Please use the above e-mail address to contact me ONLY about possible bug reports, suggestions or comments! Thank you!


COPYRIGHT NOTICE

Copyright 2004 Klemen Stirn. All Rights Reserved.

The PHPGcount may be used and modified free of charge by anyone so long as this copyright notice and the comments above 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 without prior written consent is expressly forbidden. In other words, please ask first before you try and make money off this program.

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


Requirements


>> Quick installation

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:

Save and close the graphcount.php file.

Upload graphcount.php file into a folder in your public directory (where the rest of your website is; usually "public_html", "www" or "site").
Example: /public_html/phpgcount
Corresponding URL: http://www.yourdomain.com/phpgcount/graphcount.php

Upload the "styles" folder to the same directory.
Example: public_html/phpgcount/styles
Corresponding URL: http://www.yourdomain.com/phpgcount/styles

Within the phpgcount folder create a new folder called "logs" (on many servers names are CaSe SeNsiTiVE). Make sure this folder is world-writable (on UNIX servers issue command CHMOD 777 (rwx-rwx-rwx))
Example: public_html/graphcount/logs
Corresponding URL: http://www.yourdomain.com/phpgcount/logs

Now to make your counter work just use this piece of code on your site:

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

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).
Example:
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
etc...

Try this and make sure your counter work before configuring it any more with options discussed below.


>> 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 in the graphcount.php file. 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"
and this style will be used by default.

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.


>> Enabling HTTP referer validation

Enabling HTML validation will prevent other people from using the script installed on your server to count hits on their site.

Open graphcount.php file and set $check_referer = 0; to 1 to enable HTML referer validation.
In $referers = array ("domain.com","someotherdomain.com"); set the domains you allow to use the counter.

Example of a correctly configured counter which will only allow counting hits on pages under PHPJUNKYARD.COM domain:

$check_referer = 1;
$referers = array ("phpjunkyard.com");

Save the file and upload it to 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 (equall height and widht), 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 "gcount/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!


>> Troubleshooting

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.

My counter doesn't work, HELP!

Here are a few things to check:

  1. did you create the "logs" folder (not Logs, not LOGS, not LoGs, but logs)?
  2. is the logs folder in the same folder where graphcount.php file is?
  3. is logs folder world writable? CHMOD it to 777 (rwx-rwx-rwx) if you are on a UNIX server
  4. if you enabled HTTP referer validation make sure you have also setup allowed domain(s).
  5. make sure you used the right code on your page. Change the URL in the code in this readme to the URL of your graphcount.php script.
  6. If images don't display properly (you get the [X] broken image sign) check image names, extensions and if the styles folder has been uploaded to the PHPGcount folder. Keep in mind that on most servers names are CaSe SeNSiTiVE!

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


>> 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