PHPCount - PHP text hit counter
- Version: 1.4 from 3rd March 2012
- Developed by: Klemen Stirn
- PHP text hit counter
- PHP Scripts from PHPJunkyard.com
INDEX
- Install Text hit counter
- Using hit counter
- Counting unique hits
- Upgrading from old versions
- HELP and Troubleshooting
- Newsletter, rating this script and other
- Changelog
- Copyright notice and license
» ACKNOWLEDGEMENT
Please support developing of free PHP scripts 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:
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
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/counterUpload all counter files and folders to your server in ASCII mode.
TIP: Most FTP clients will select the proper transfer mode automatically.
-
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.
-
Test the counter by opening counter.php?page=test in your browser, for example:
http://www.yourwebsite.com/counter/counter.php?page=testYour browser should show something like
document.write('1');
Got an error message instead? See below under HELP and Troubleshooting.
» Using PHP text hit counter
To use the hit counter on your website you need to:
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 "-"
- 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-).
- To start counting visitors place this code in your web page:
<script language="Javascript" src="http://www.site.com/counter/counter.php?page=test"><!-- //--></script>
Change http://www.site.com/counter/counter.php to the URL address of counter.php on your server, for example:
http://www.yourwebsite.com/counter/counter.phpChange test to the name of a text file you created in Step 1 (without ".txt"), for example:
http://www.yourwebsite.com/counter/counter.php?page=indexTIP: Not sure how to paste Javascript code into your website? See this tutorial:
Cut and paste code into HTML document Open your website and there should be a number (count) displaying where the Javascript code has been pasted.
» Counting UNIQUE hits
If you wish to count unique visits (hits) only, open file counter.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 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.
» 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
- Upload the new counter.php file to your server
From version 1.0, 1.1 or 1.2
- Rename all files inside "logs" from name.log to name.txt
- 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-).
- 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. 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 counter.php file must be called with a ?page=PAGEID parameter
Your are missing ?page=PAGEID in your Javascript code behind counter.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:
- 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!
- 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.
- 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:
- Help Desk Software
- Click and download counter
- Reciprocal links manager
- Guestbook
- Message board
- Text hit counter (this script)
- Graphical hit counter
- Random image
- Random text
» CHANGELOG
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 NOTICE
Copyright 2004-2012 Klemen Stirn. All Rights Reserved.
The PHP Counter 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.