Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

How To Connect My Download Button With A Counter?

I Wanna Make It Where When Someone Clicks The Download Button, The Counter On Tye Page Tells Me How Many Times Its Been Downloaded!! Help Me!!
http://stackoverflow.com/questions/11195...oad-button
FS Webdeveloper
Create a counter variable and print the variable. Add one to the value on button interaction.

[Image: qZ42qWp.jpg]

(Jun 30, 2016 12:57 PM)ihatevim Wrote:  Create a counter variable and print the variable. Add one to the value on button interaction.

Sherlock holmes in the house right here
FS Webdeveloper
On click
$Variable++;

That's not code. That's just the principle of it. I'm currently at work and on mobile, but this should point you in the right direction.
(Jun 30, 2016 12:59 PM)SteezyHB Wrote:  Sherlock holmes in the house right here

God forbid someone provides the pseudocode as opposed to posting the first link they google'd.

[Image: qZ42qWp.jpg]

Or you can do it with a form, using database. This way you can use that number everywhere.
[Image: TrJCrgs.jpg]
Just update a database entry when the botton is client to an int stored in the db as counter.
When someone clicks on the link it should point to a PHP file that reads a file with one single number in it, add +1 to the number and overwrite the file with the number, then redirect to the actual file with header().
You see, Doctor, God didn't kill that little girl. Fate didn't butcher her and destiny didn't feed her to those dogs.
If God saw what any of us did that night he didn't seem to mind. From then on I knew... God doesn't make the world this way.
We do.
(Jul 1, 2016 06:42 AM)Squito Wrote:  When someone clicks on the link it should point to a PHP file that reads a file with one single number in it, add +1 to the number and overwrite the file with the number, then redirect to the actual file with header().

I like this approach.

Create 2 new files:
  • download.php

  • counter.txt (leave blank)



Example code for download.php;
PHP Code

<?php
$count 
= file_get_contents('counter.txt');
$f = fopen('counter.txt', 'w+');
fwrite($f, $count + 1);
fclose($f);

header("Location: downloadfile.zip");
?>

Then you can just link the download.php file where your download button is using a simple code, for example;
Code
<a href="download.php">Download</a>

To display the number of downloads;
PHP Code

<?php echo file_get_contents( "counter.txt" ); ?>
(Jul 1, 2016 10:07 AM)SIM-545076 Wrote:  Create 2 new files:
  • download.php

  • counter.txt (leave blank)



You mean create a counter.txt with the content: 0. Also make sure that the counter.txt is writable (666 or 777 rights).
You see, Doctor, God didn't kill that little girl. Fate didn't butcher her and destiny didn't feed her to those dogs.
If God saw what any of us did that night he didn't seem to mind. From then on I knew... God doesn't make the world this way.
We do.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by Wide AwakeDec 23, 2015 09:13 AM 4 121 Dec 23, 2015 09:13 AM
Last Post: .trigious
by King‎‎‎‎‎‎Oct 28, 2015 01:49 AM 6 152 Oct 28, 2015 01:49 AM
Last Post: ShizzleFly
by leemoriMar 29, 2014 03:38 PM 1 66 Mar 29, 2014 03:38 PM
Last Post: redpenguin