Il mio script è diverso ma il problema è questo:
Codice PHP:
<?php
class Problema {
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 )) {
$v = file_get_contents ( $file ) + 1;
}
file_put_contents ( $file, $v, LOCK_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>
Quando clicco sul pulsante incremento la visita, cosa che non vorrei che accadesse. Vorrei che il numero dentro il file si incrementasse solo quando accedo direttamente alla pagina o faccio un reflesh e non anche quando ci ritorno cliccando sul pulsante "indietro" del browser.
Ciao