Non funziona!
Somma sempre 1 sia quando apro il file, sia quando faccio un refresh:
Codice PHP:
<?php
class Problema {
    public function 
Init() {
        
session_start ();
        
$_SESSION ['contavisite'] = 'ok';
    }
    public function 
Leggi($file) {
        if (
file_exists $file )) {
            
header 'Content-Description: File Transfer' );
            
header 'Content-Type: text/plain; charset=UTF-8' );
            
header "Expires: on, 01 Jan 1970 00:00:00 GMT" );
            
header "Last-Modified: " gmdate "D, d M Y H:i:s" ) . " GMT" );
            
header "Cache-Control: no-store, no-cache, must-revalidate" );
            
header "Cache-Control: post-check=0, pre-check=0"false );
            
header "Pragma: no-cache" );
            
header 'Content-Length: ' filesize $file ) );
            
readfile $file );
            exit ();
        }
    }
    public function 
Download($file) {
        
$this->Leggi $file );
    }
    public function 
PreparaDownload() {
        
$variabilePOST "x";
        if (isset ( 
$_POST [$variabilePOST] )) {
            
$file "file.txt";
            
$this->Download $file );
        }
    }
    public function 
VisiteNonUniche() {
        
$file "file.txt";
        
$v 1;
        if (
file_exists $file )) {
            if (! isset ( 
$_SESSION ['contavisite'] )) {
                
$this->Init ();
                if (isset ( 
$_POST ['x'] )) {
                    
$v file_get_contents $file );
                } else {
                    
                    
$v file_get_contents $file ) + 1;
                    
                }
            }
        }
        
file_put_contents $file$vLOCK_EX );
        return 
$v;
    }
}
$Prova = new Problema ();
$VisiteNonUniche $Prova->VisiteNonUniche ();
$Prova->PreparaDownload ();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Problema</title>
</head>
<body>
    <p>Visite: <?php print_r($VisiteNonUniche)?></p>
    <form action="" method="post">
        <input type="submit" value="Visualizza file" name="x">
    </form>
</body>
</html>