RE: [PHP] Counter

From: Date: Tue, 25 Sep 2001 16:45:47 +0000
Subject: RE: [PHP] Counter
Groups: php.general 
Request: Send a blank email to php-general+get-68733@lists.php.net to get a copy of this message
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:mark@3dsources.com] 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: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net ********************************************************************** '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' **********************************************************************

« previous php.general (#68733) next »