RE: [PHP] writting into a text file

From: Date: Fri, 21 Sep 2001 21:31:10 +0000
Subject: RE: [PHP] writting into a text file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68219@lists.php.net to get a copy of this message
<?php $COUNT_FILE = "div/count_data.txt"; if (file_exists($COUNT_FILE)) { // En: Open, read, increment, save and close file. $fp = fopen("$COUNT_FILE", "r+"); flock($fp, 1); $count = fgets($fp, 4096); $count += 1; fseek($fp,0); fputs($fp, $count); flock($fp, 3); fclose($fp); } else { // En: Display a error message if file does not exist. echo "Can't find file, check '\$file' var...<BR>"; } ?> I prefer to store that code in a separate document and include it in the documents i want it. Change $COUNT_FILE to whatever suits you. It's just a empty textfile from the start. Don?t forget to chmod the textfile properly. Then you just have to echo $count; # Daniel Alsen | www.mindbash.com # # d@mindbash.com | +46 704 86 14 92 # # ICQ: 63006462 | # > I am having a problem that looks like this : > 1.I'd like to have some clue on the traffic on my site, but my > server doesn't support > the mysql or smth like that. Anyway, I'd be happy with a text > file, smth like a log > file. Is it possible to write into a text file ? > 2. Is it possible and is it a right way to do so : Making a > counter based on the > system I explained in the 1st question : writting a number into a > text file, and on > every hit, reading it and increasing by 1.... ?

« previous php.general (#68219) next »