PHPCount - PHP text hit counter



Please support free PHP script development by linking to us or sending a donation. Thank you!

» Install Text 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:

  3. Upload all counter files and folders to your server in ASCII mode.

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

  4. Test the counter by opening counter.php?page=test in your browser, for example:

    Your browser should show something like

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

» Using PHP text hit counter

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

    Use only letters (a-z, A-Z), digits (0-9), dots ".", underscores "_" and hyphens "-", like this:


  2. Upload the text files into the logs folder to your server.
  3. To start counting visitors place this code in your web page:

    <script src=""></script>

    Change to the URL address of counter.php on your server.

    Change test to the name of a text file created in Step 1 (without ".txt").

    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, the count should display where the Javascript code has been pasted.

» Counting UNIQUE hits

To count unique visits only, open file counter.php in a plain text editor.

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 counter.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 counter.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 counter.php file to your server.

» Formating thousands

By default, counter will separate thousands with a comma, for example:

To use a different thousands separator, modify this variable inside counter.php:

$thousands_separator = ',';

Some examples:

$thousands_separator = '.';
Will show: 1.999.999

$thousands_separator = ' ';
Will show: 1 999 999

$thousands_separator = '';
Will show: 1999999

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

» 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.3 and 1.4

  1. Upload the new counter.php file to your server

From version 1.0, 1.1 or 1.2

  1. Rename all files inside "logs" from name.log to name.txt
  2. Upload the new counter.php file to your server

» 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. ERROR: Not writable. PHP needs permission to write to file logs/test.txt

PHP does not have permission to read or write to a log file.

On Linux servers CHMOD log files to 666 (rw-rw-rw-).

On Windows IIS servers give Internet Guest Account (IUSR) permission to modify, write and read log files.

If this error persists, ask your hosting company to set correct file permissions.

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

Your are missing ?page=PAGEID in your Javascript code behind counter.php, see 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 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).

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


Changes in 1.6
- fixed missing quote in example code

Changes in 1.5
- added thousands separator

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

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

Changes in 1.2
- improved input parameter checking
- added file locking
- added zero-padding option

Changes in 1.1
- added support for counting unique hits
- no more automatic file creation (for security reasons)
- removed referrer check (not really needed anymore)


© Copyright Free PHP Scripts 2004-2014. All rights reserved.