Actually.. that is how I am doing it:
<script language="Javascript">
<!--
doc=document;
doc.write("<img src=\"http://www.domain.com");
doc.write("/stats/count.php?");
doc.write("account=myaccount&referer=");
doc.write(escape(top.document.referrer));
doc.write("\" width=1 height=1 align=\"right\">");
// -->
</script>
Ofcourse that doesn't show anything, so after that I simply place a img tag that shows a nice icon of the counter.
The best way to do it is use GD library. However, although this works perfectly locally on my NT 4 server, it fails on the remote webserver. I think it's because of some security problem, e.g. the system has no rights to create a tmp file to process the image.
This is a bit quick and dirty but it works, and it works on all systems.
count.php get's it's referrer and account name from the javascript and inserts the results in the accounts name table.
One down side:
If the user disables javascript, no counting takes place ;-(
However:
Your entrance page doesn't need to be .php since it's simple javascript that works in .php/.html/.asp as long as count.php can be reached.