I have made a really simple counter. It stores the number of visits in a text file. But for some reason it adds 3 ever time you do a refresh in stead of 1. Can anyone explain why? This is the function I am calling:

PHP Code:
function total_page_views(){

    
$tot_user_file $path '/totalusers.txt';

    
$totuser_handle fopen($tot_user_file'r+') or die("can't open file");
    
flock ($totuser_handleLOCK_EX); 
    
    if (
filesize($tot_user_file) > 0){
    
$totusers fread($totuser_handlefilesize($tot_user_file));
        
$totusers ++;
    }else{
    
$totusers 1;
    }

    
$totuser_handle fopen($tot_user_file'w+') or die("can't open file");
    
fwrite($totuser_handle$totusers);    
    
    
flock ($totuser_handleLOCK_UN);
    
fclose($totuser_handle);

    return 
$totusers;



And I have split up the index file in 3 parts. So it is the index.php file, the top.php and the bottom.php. The index.php includes the top.php in the top, and the bottom.php on the bottom. So in the top.php file I have something like this:

PHP Code:
<?php
require "functions/counter.php";

echo 
'            <div id="banner">' total_page_views() . '</div>';

?>

A bit awkvard I know...but hmm...anyone see what I might be doing wrong???



- ØØ -