here you go:
PHP hit counter
Just the basic outline so you can understand what the code means;
- Anything with a $ in front of it is a variable, it is either being assigned or being displayed
- Page 2 is optional, leave it out if you want an invisible counter, just make sure you add the very first line of it to the page you want counted (the <?php include... ?> one) at the top of your document.
- The stuff between the <? and ?> is the php code, and can be put inside another document or linked to as a separate one.
- To use php scripts in a html document (not as a standalone one), the eaisest way is to rename your file from .html to .php
What the script does: The file countFunction.php is a file that is separate from everything else and linked to from your index.php page (make sure your page is index.php not index.html). When the browser loads the page it also loads and executes that file. The php code asks the browser if the user has been counted already (in the current session) and if not, writes to the file counter.txt the new number of visitors.
Something I find really useful but is completely unrelated: If you have a site where the same thing appears on each page but changes often (i.e. a news bar on the side or something you want to spotlight), put the corresponding code with all the html tags into a file, yourfilenamehere.txt. Take it out of the original page, and put this line of code into where you want the information displayed: <?php include "yourfilenamehere.txt"; ?>. Change index.html or whatever page it is to index.php and you're away. If you change the text file it will change the html file. So you can add this piece of code to any page you want and it will always display the same.
[edit]Oops, for the function to be called that does all the work, you will
need to have the line <?php Counter(); ?> in there somewhere... but this will display the number of hits. Edit the last line "echo $finalcount" out of countFunction.php.