It's very simple - at the top of every page, have a routine that opens a
text file, reads the number inside it into a variable, adds one, and writes
it back out again. If the text file doesn't exist, create it.

Psuedocode:

if (file exists) {
  open file for reading;
  read contents into $counter;
  increase $counter by 1;
} else {
  set $counter to 1;
  open file for writing;
}
write $counter to file;
close file;
print "you are visitor number $counter.";

Look into fopen(), fread(), fwrite() and friends. Of course, it's now up to
you to work out how you're going to count cached requests, search engine
bots, link checkers, etc etc. Personally I reckon you're better off with
this:

<?php
mt_srand((double)microtime()*1000000);
$counter = mt_rand(1, 999999999);
echo "You are visitor number $counter.";
?>


Cheers
Jon


-----Original Message-----
From: Mark Lo [mailto:[EMAIL PROTECTED]]
Sent: 25 September 2001 16:50
To: php general
Subject: [PHP] Counter


Hi,

        I would like to know how to write a web page counter in PHP or
Javascript.

Thank You

Mark Lo


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



**********************************************************************
'The information included in this Email is of a confidential nature and is 
intended only for the addressee. If you are not the intended addressee, 
any disclosure, copying or distribution by you is prohibited and may be 
unlawful. Disclosure to any party other than the addressee, whether 
inadvertent or otherwise is not intended to waive privilege or confidentiality'

**********************************************************************

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to