Button "Like/Like"

Asked

Viewed 1,379 times

3

I want to make a button on my site with a counter next to it and I would like every click the counter to increase 1 number. But I wanted to save that number of clicks on a file .txt on the server, and that everyone could click and see this counter.

A button Like, that could only be clicked 1 time per computer. Understand? I want users to rate the content of my site with this button.

  • 1

    PHP, Nodejs, ASP... which server-side language? and which database?

  • I wish you wouldn’t use a database, and the number was saved in a text file.

  • Okay, and what server-side language do you have? PHP, Nodejs, ASP...

  • PHP. :) Thank you Sérgio.

1 answer

5


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

  • Thanks! I got what I wanted!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.