Location: PHPKode > scripts > PHPCount-PHP Text hit counter > readme.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML; 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>PHP text hit counter - README</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/* Style sheet and XHTML code
Author: Mauricio Samy Silva http://www.maujor.com/ A Web Standard evangelist site
City: Rio de Janeiro - Brazil
Contact: maujorcss[at]maujor[dot]com
Date: 2006-05-11
*/
body {
        margin:5px 0;
        padding:0;
        background:#eee;
        color: black;
        font : 68.8%/1.5 Verdana, Geneva, Arial, Helvetica, sans-serif;
        text-align:center;
        }
#wrapper {
        width:700px;
        background:#fff;
        margin:0 auto;
        text-align:left;
        border:1px solid #ccc;
        padding:10px 20px;
        }
h1 {
        font-size:1.5em;
        }
h2 {
        font-size:1.2em;
        border-top:1px solid #999;
        padding-top:1.8em;
        }
h3 {
        font-size:1.0em;
        }
span.dest { color:#f00;}
span.tip { color:#008000; font-weight:bold;}
p {
        color : black;
        font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
        font-size: 1.0em;
        }
address {
        font-weight:bold;
        font-style:normal;
        }
ul.nobullets {
        margin:0 0 1.0em;
        padding:0;
        list-style:none;
        }
ol li {margin-bottom:1.0em;}
samp, code {
        font-size:1.3em;
        font-weight:bold;
        }
a:hover {
        color : red;
        background:#ccc;
        text-decoration : none;
        }
table#installation {
        border-collapse:collapse;
        margin: 5px 15px 10px -25px;
        border: 2px solid #999;
        }
table#installation thead {
        text-align:center;
        text-transform:uppercase;
        }
table#installation tr td, table#installation tr th {
        padding: 2px 5px;
        border: 1px solid #ccc;
        }
table#installation tr th {
        border-bottom-width:2px;
        border-bottom-color:#999;
        }

table#installation tr td var {
        font-weight:bold;
        font-style:normal;
        }
table#installation tr.odd {
        background: #fafafa;
        }


</style>
</head>
<body>
<div id="wrapper">
<div id="main">
<h1><span class="dest">PHPCount</span> -
PHP text hit counter</h1>

<ul class="nobullets">
<li>Version: 1.3 from 21st August 2009</li>
<li>Author: Klemen Stirn</li>
<li><a href="http://www.phpjunkyard.com/php-text-hit-counter.php" target="_blank">PHP text hit counter</a></li>
<li><a href="http://www.phpjunkyard.com" target="_blank">PHP Scripts from PHPJunkyard.com</a></li>
<li><a href="http://developers.phpjunkyard.com/" target="_blank">Support and developers forum</a></li>
</ul>

<h2>INDEX</h2>

<ul class="nobullets">
    <li><a href="#copy">Copyright notice and license</a></li>
    <li><a href="#desc">Description &amp; requirements</a></li>
    <li><a href="#install">Installation</a></li>
    <li><a href="#upgrade">Upgrading from old versions</a></li>
    <li><a href="#help">HELP and Troubleshooting</a></li>
    <li><a href="#other">Newsletter, rating this script and other</a></li>
</ul>

<h2 id="copy">COPYRIGHT NOTICE</h2>

<p>Copyright 2004-2009 Klemen Stirn. All Rights Reserved.</p>
<p>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.</p>
<p><b>Selling the code for this program, in part or full, without prior written consent is expressly forbidden.</b></p>
<p><b>Obtain permission before redistributing this software over the Internet or in any other medium.</b> 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.</p>

<h2 id="desc">DESCRIPTION</h2>

<p>PHPcount is a simple PHP text hit counter. It uses flat text database so no MySQL is 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.</p>

<p><b>Changes in 1.3</b><br />
- fixed a bug with counting unique visits over several pages</p>

<p><b>Changes in 1.2</b><br />
- improved input parameter checking<br />
- added file locking<br />
- added zero-padding option</p>

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

<h2>REQUIREMENTS</h2>

<ul>
    <li>PHP 4.3 or newer</li>
</ul>

<h2 id="install">&raquo; Installation</h2>

<p style="font-weight:bold"><span class="dest">Please take 5 minutes time and read installation instructions carefully and completely! This will ensure a proper and easy installation.</span></p>

<p style="font-weight:bold"><span class="dest">If you have problems/questions see the &quot;HELP and Troubleshooting&quot; section further down.</span></p>

<ol>
<li>
<p>FTP to the public folder of your server (where the rest of your website is;
usually called &quot;public_html&quot;, &quot;www&quot; or &quot;site&quot;) and create
a folder where you will install PHPCounter (for example named &quot;counter&quot;).<br />
Example: /public_html/counter<br />
Corresponding URL: http://www.yourdomain.com/counter</p>
<p><span class="tip">TIP:</span> If you don't know how to FTP or CHMOD files read my simple
<a href="http://www.phpjunkyard.com/ftp-chmod-tutorial.php" target="_blank">FTP and CHMOD tutorial</a></p>
</li>
<li>
<p>Upload all PHPCounter files and folders to your server in ASCII mode.</p>
</li>
<li>
<p>Make sure file <b>test.txt</b> inside &quot;logs&quot; folder is writable by PHP scripts. On Unix (Linux) servers CHMOD this file to <b>666</b> (rw-rw-rw-).</p>
</li>
</ol>

<p>That's it. To test if PHPCounter works fine open <i>counter.php?page=test</i> in your browser, for example:<br />
http://www.yourdomain.com/counter/counter.php?page=test</p>

<p>Your browser should show something like:</p>
<p><b>document.write('1');</b></p>

<p>Got an error message? A few solutions can be found below under <a href="#help">HELP and Troubleshooting</a>.</p>

<p><b>Using PHP text hit counter</b></p>

<p>To use PHP Counter on your page(s) you need to:</p>

<ol>
<li>Create an empty text file for each unique page you want to count visits on. For example
create files called <b>page1.txt</b>, <b>page2.txt</b>, <b>mypage.txt</b>, <b>somelongname.txt</b>,... Try using
letters (a-zA-Z) and digits (0-9) only.</li>
<li>Upload these text files into the <b>logs</b> folder to your server and make
sure PHP scripts have permission to write to these files. On Unix (Linux) servers CHMOD this file to <b>666</b> (rw-rw-rw-).</li>
<li>To start counting visitors place this code on your site:</p>
<p>&lt;script language=&quot;Javascript&quot; src=&quot;http://www.domain.com/counter/counter.php?page=PAGENAME&quot;&gt;&lt;!--<br>
//--&gt;&lt;/script&gt;</p>
<p>Change the <i>src</i> parameter accordingly (to the counter.php on your server)! Change PAGENAME to a name of a text file (<b>without</b> &quot;.txt&quot;)
you uploaded to the &quot;logs&quot; folder above.</p>
<p>For example set src to:<br />
http://www.domain.com/counter/counter.php?page=mypage<br />
This will log visits into file mypage.txt which must be uploaded into &quot;logs&quot; folder</p>
<p><span class="tip">TIP:</span> Not sure how to correctly paste Javascript code into your website? See my
<a href="http://www.phpjunkyard.com/tutorials/cut-paste-code.php" target="_blank">Cut and paste code into HTML document</a> tutorial.</p>
</li>
</ol>

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

<p><b>Counting UNIQUE hits</b></p>

<p>If you wish to count unique visits (hits) only, then open file <b>counter.txt</b> in a plain
text editor (like Notepad or Wordpad in Windows). Inside find line:<br />
$count_unique = <b>0</b>;<br />
and change it to:<br />
$count_unique = <b>1</b>;</p>

<p>By changing the value for <i>$unique_hours = 24;</i> 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 <i>$unique_hours = 12;</i></p>

<p>Save changes and upload the edited counter.php file to your server.</p>

<p><b>Zero-padding (minimum digits to display)</b></p>

<p>Want your counter to display a minimum number of digits? For example
display count <b>123</b> as <b>00123</b>? No problem, open file <b>counter.php</b> in a plain
text editor (like Notepad or Wordpad in Windows). Inside find line:<br />
$min_digits = 0;<br />
and change the 0 to the minimum number of digits you want to display. For example to
disply minimum 5 digits set it to:<br />
$min_digits = <b>5</b>;</p>

<p>To disable zero-padding simply change $min_digits back to <b>0</b></p>

<p>Save changes and upload the edited counter.php file to your server.</p>

<h2 id="upgrade">&raquo; Upgrading from old versions</h2>

<p style="font-weight:bold"><span class="dest">Please take 5 minutes time and read upgrade instructions carefully and completely! This will ensure a proper and easy upgrade.</span></p>

<ol>
<li>Rename all files inside &quot;logs&quot; from name.<b>log</b> to name.<b>txt</b></li>
<li>Make sure PHP scripts can write to files inside &quot;logs&quot; folder. On Unix (Linux) servers CHMOD these files to <b>666</b> (rw-rw-rw-).</li>
<li>Upload the new counter.php file to your server</li>
</ol>

<p>That's it, you are ready to go!</p>

<h2 id="help">&raquo; HELP and Troubleshooting</h2>

<h3>1. What is CHMOD and FTP?</h3>

<p>I have prepared a simple <a href="http://www.phpjunkyard.com/ftp-chmod-tutorial.php" target="_blank">FTP
and CHMOD tutorial</a> which will help you FTP files to your server and set correct CHMOD settings.</p>

<h3>2. I get an ERROR saying &quot;Can't write to the log file, please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!&quot;</h3>

<p>PHP script doesn't have permission to write to your file(s). Make sure PHP scripts have permission
to write to all files inside &quot;logs&quot; folder. On Unix (Linux) servers CHMOD these files to <b>666</b> (rw-rw-rw-).
If you are not sure how, see my <a href="http://www.phpjunkyard.com/ftp-chmod-tutorial.php" target="_blank">FTP
and CHMOD tutorial</a>.

<h3>2. I get an ERROR saying &quot;Invalid log file!&quot;</h3>

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

<ol>
<li>Did you create an empty text file? If you are calling the script with <i>counter.php?page=<b>mypage</b></i>
you need to have an empty text file called <b>mypage.txt</b> inside your &quot;logs&quot;
folder!</li>
<li>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.</li>
<li>Did you use any special characters in your file name? Try naming the files
only with letters (a-zA-Z) and digits (0-9).</li>
</ol>

<p>&nbsp;</p>

<p>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 <a href="http://developers.phpjunkyard.com">PHPJunkyard forum</a>!</p>

<h2 id="other">&raquo; Stay updated!</h2>

<p>Join my FREE newsletter and you will be notified about new scripts, new versions of the existing scripts and other important news from PHPJunkYard.<br />
<a href="http://www.phpjunkyard.com/newsletter.php" target="_blank">Click here for more info</a></p>

<h2>&raquo; Please rate this script</h2>

<p>If you like this script please rate it or even write a review at:</p>

<p><a href="http://php.resourceindex.com/detail/05193.html" target="_new">Rate this Script @ The PHP Resource Index</a></p>

<p><a href="http://www.hotscripts.com/Detailed/36871.html" target="_blank">Rate this Script @ Hot Scripts</a></p>

<h2>&raquo; Get more useful FREE scripts!</h2>

<p>Looking for more <a href="http://www.phpjunkyard.com" target="_blank">PHP scripts</a>? Here is a list of PHPJunkyard FREE scripts:</p>

<ul>
<li><a href="http://www.hesk.com" target="_blank">Help Desk Software</a></li>
<li><a href="http://www.phpjunkyard.com/php-click-counter.php" target="_blank">Click and download counter</a></li>
<li><a href="http://www.phpjunkyard.com/php-link-manager.php" target="_blank">Reciprocal links manager</a></li>
<li><a href="http://www.phpjunkyard.com/php-guestbook-script.php" target="_blank">Guestbook</a></li>
<li><a href="http://www.phpjunkyard.com/php-message-board.php" target="_blank">Message board</a></li>
<li><a href="http://www.phpjunkyard.com/php-text-hit-counter.php" target="_blank">Text hit counter</a> (this script)</li>
<li><a href="http://www.phpjunkyard.com/php-graphical-hit-counter.php" target="_blank">Graphical hit counter</a></li>
<li><a href="http://www.phpjunkyard.com/random-image.php" target="_blank">Random image</a></li>
<li><a href="http://www.phpjunkyard.com/random-text.php" target="_blank">Random text</a></li>
</ul>

<p>&nbsp;</p>

<p style="text-align:center">&copy; Copyright <a href="http://www.phpjunkyard.com">PHP Scripts from PHPJunkyard</a> 2004-2009. All rights reserved.</p>

</div>
</div>
</body>
</html>
Return current item: PHPCount-PHP Text hit counter