count_download.php
Codice PHP:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$text = "$ip\n";
$fp = fopen('counter.txt', 'a+');
fwrite($fp, $text);
fclose($fp);
header("location: download_ciao.php");
?>
download_ciao.php
Codice PHP:
<?php
$file = "file.mp3";
header("Cache-Control: public");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: audio/mp3");
readfile($file);
?>
read_visit.php
Codice PHP:
<?php
$file = "counter.txt";
if(file_exists($file)){
$f = file($file);
$n = count($f);
$volte = "volte";
if ($n == 1){
$volte = "volta";
}
$num_download = "$n $volte";
} else {
$num_download = "0 volte";
}
?>
<?php echo"$num_download"; ?>
<a href="count_download.php">cliccami!</a>
counter.txt
Codice:
Ho provato ad inserire 0, 1 o nulla ma non cambia niente