<?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 #
# [EMAIL PROTECTED]  | +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.... ?


-- 
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