Three files will be used:
1 - main.php, which will display the download link and the number of downloads
2 - download_file.php - This will increase the counter by 1, download the file and redirect to the main.php
3 - counter_file.txt - Store the number of downloads
FILE 1 - MAIN.PHP:
<html>
<body>
<a href="download_arquivo">DOWNLOAD AQUI</a>
<br>N. de Downloads: <? include "contador_arquivo.txt"; ?>
</body>
</html>
FILE 2 - DOWNLOAD_ARQUIVO.PHP
<html>
<body>
<a href="java script:history.back(-1)">">Voltar</a>
<?php
//Abre o contador de downloads e acrescenrta em 1
$fp = fopen("contador_arquivo.txt","r");
$visitas = fgets($fp,255);
$visitas++;
fclose($fp);
$fp = fopen("contador_arquivo.txt","w+");
fwrite($fp, $visitas);
fclose($fp);
?>
<script language="JavaScript">
//Redireciona para o arquivo de download
location.href="SEU_ARQUIVO.ZIP";
</script>
FILE 3 - CONTADOR_ARQUIVO.TXT
(escreva o numero 0 e salve o arquivo)
Source: Contador Clicks
PHP, Nodejs, ASP... which server-side language? and which database?
– Sergio
I wish you wouldn’t use a database, and the number was saved in a text file.
– Hugo Marcelo
Okay, and what server-side language do you have? PHP, Nodejs, ASP...
– Sergio
PHP. :) Thank you Sérgio.
– Hugo Marcelo