I have an old CGI counter that has always worked for me. I will post the code.
Place both files in your /cgi-bin/ directory.
counter.cgi (CHMOD 755)
CODE
#!/usr/bin/perl
#change first line to proper perl location.
###########################################
#Very simple PERL text based counter.
#upload this script to your cgi-bin directory and chmod to 755.
#to use it simple add this code to your html.
#<script language="javascript" src="http://yourdomain.com/cgi-bin/counter.cgi"></script>
#If you have problems you can contact webmaster@dony.com.kg
#This script is free of charge. Do not hesitate to suggest this script to your friends.
#Thanks for using this script.
#www.dony.com.kg
###########################################
$log="counter.txt"; #counter file.
#nothing else to change leave it as is.
open (FILE,$log);
$counter=<FILE>;
close(FILE);
$counter++;
open (WRITE,">$log");
print WRITE "$counter";
close(WRITE);
print "Content-type: text/html\n\n";
print "document.write($counter)";
Please make sure to update $log=""; with whatever the name of your counter file is. If you have just the one, might as well just keep it as counter.txt as I have it.
counter.txt (CHMOD 755)
CODE
1
Since counter.txt will contain the current count, make this number whatever you wish. Just remember that you must have plain numbers (e.g. 12365478 --not-- 123,456,789).
Code to increment the counter and display the result
CODE
<script language="javascript" src="http://www.yourdomain.com/cgi-bin/counter.cgi"></script>
Change the src to your sites source. This will print out a simple text hit counter.
Hope this helps! I know that its not php, but it works great!