12 Replies - 34586 Views - Last Post: 02 April 2016 - 01:06 PM

#1 angelo dundee  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 29-June 05

How do I count downloads from my website ?

Posted 09 August 2005 - 08:40 AM

I have some simple programs on my web site, for download :-
www.engineeringspreadsheets.co.uk, see Sling Design Program

When a user presses the link ' Free Demo Version' to download a program, how can I provide some sort of counter, which tells me how many times the program has been downloaded ?

:rolleyes: :blink:

Is This A Good Question/Topic? 0
  • +

Replies To: How do I count downloads from my website ?

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 249
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: How do I count downloads from my website ?

Posted 09 August 2005 - 08:56 AM

What scripting language are you using? You can increment a counter in a database everytime someone downloads, or write the updated number to a file.
Was This Post Helpful? 1

#3 lattyware  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 08-August 05

Re: How do I count downloads from my website ?

Posted 09 August 2005 - 10:21 AM

Some very simple PHP would be the best option here.

<?php
$Down=$_GET['Down'];
?>

<html>
<head>
<meta http-equiv="refresh" content="0;url=<?php echo $Down; ?>">
</head>
<body>

<?php

$fp = fopen("Count.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;

//Un-comment to display the downloads.
echo "Downloads:" . $count . "";

$fp = fopen("Count.txt", "w");
fwrite($fp, $count);
fclose($fp);

?> 

</body>
</html>




Call it download.php and then put a link to 'download.php?Down=download.zip'
Simple enough, and the number of donwloads will be stored in a text file.

I have made a version to try out here: http://www.lattyware.co.uk/Test/
The download is a zipped set of the files.

This post has been edited by lattyware: 09 August 2005 - 10:22 AM

Was This Post Helpful? 2

#4 angelo dundee  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 29-June 05

Re: How do I count downloads from my website ?

Posted 23 August 2005 - 11:23 AM

My website package supports :-
Java
Perl 5.0
Private CGI-bin
PHP 4.1.2.
Was This Post Helpful? 1
  • +
  • -

#5 spacebar22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-December 12

Re: How do I count downloads from my website ?

Posted 13 December 2012 - 09:16 PM

Hi

Trying not to ask you do to my homework for me... This post was very useful (it works fine). What would be the best approach to extend this to multiple downloads per page? Ideally with only one Count.txt, but separate lines in that file for each download.Or separate count files would be fine too. Is there a good php function where I can specify the file name and then the action required for that name?
Was This Post Helpful? 0
  • +
  • -

#6 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 220
  • View blog
  • Posts: 1,606
  • Joined: 20-January 09

Re: How do I count downloads from my website ?

Posted 13 December 2012 - 09:49 PM

You could build an array for file names and their counts, and since you said that this is homework I'll let you start, post your code if you run into a problem.

This post has been edited by gregwhitworth: 13 December 2012 - 09:50 PM

Was This Post Helpful? 0
  • +
  • -

#7 sjgreen184  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 16

Re: How do I count downloads from my website ?

Posted 30 March 2016 - 09:34 AM

View Postlattyware, on 09 August 2005 - 10:21 AM, said:

Some very simple PHP would be the best option here.

<?php
$Down=$_GET['Down'];
?>

<html>
<head>
<meta http-equiv="refresh" content="0;url=<?php echo $Down; ?>">
</head>
<body>

<?php

$fp = fopen("Count.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;

//Un-comment to display the downloads.
echo "Downloads:" . $count . "";

$fp = fopen("Count.txt", "w");
fwrite($fp, $count);
fclose($fp);

?> 

</body>
</html>




Call it download.php and then put a link to 'download.php?Down=download.zip'
Simple enough, and the number of donwloads will be stored in a text file.

I have made a version to try out here: http://www.lattyware.co.uk/Test/
The download is a zipped set of the files.


This works, but has one problem - if the php page is loaded in a browser, it iterates over the script causing the count to increase rapidly (like several per second). Any idea how to avoid this?
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6317
  • View blog
  • Posts: 29,984
  • Joined: 10-May 07

Re: How do I count downloads from my website ?

Posted 30 March 2016 - 09:36 AM

View Postsjgreen184, on 30 March 2016 - 11:34 AM, said:

Any idea how to avoid this?

Yes, not implementing code 11 years old.

I wouldn't do anything suggested here. Meta refresh is incredibly unreliable solution for forcing a client browser's behavior.
Was This Post Helpful? 0
  • +
  • -

#9 sjgreen184  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 16

Re: How do I count downloads from my website ?

Posted 30 March 2016 - 09:47 AM

Thanks for quick reply. I take your point but spent ages trying to find a script to count downloads and this was the only one I could get to work at all. Reckon this will have to do for the time being. At least it should be apparent if the script is being left running as I will end up with more downloads than website hits (which my host records)!
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6317
  • View blog
  • Posts: 29,984
  • Joined: 10-May 07

Re: How do I count downloads from my website ?

Posted 30 March 2016 - 10:02 AM

If your host is recording page hits, here is what I would do :

download page -> client clicks download
mod_rewrite server side -> specific page -> download to client
Add "specific page" to robots.txt to disallow robots to hit the file

Now check with your host, every hit to that page is your number of downloads.

Another way to do this is to increment a number in a database. For each "click", ajax back to server_downloads.php, which gets the value from the db entry, increments, & saves the new value.
Was This Post Helpful? 0
  • +
  • -

#11 sjgreen184  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 16

Re: How do I count downloads from my website ?

Posted 30 March 2016 - 01:20 PM

View Postno2pencil, on 30 March 2016 - 10:02 AM, said:

If your host is recording page hits, here is what I would do :

download page -> client clicks download
mod_rewrite server side -> specific page -> download to client
Add "specific page" to robots.txt to disallow robots to hit the file

Now check with your host, every hit to that page is your number of downloads.

Another way to do this is to increment a number in a database. For each "click", ajax back to server_downloads.php, which gets the value from the db entry, increments, & saves the new value.


Thanks very much for the suggestions! Regarding the first one, I'm pretty sure it is just total hits for my whole website that my host records - not for individual pages. Regarding the second one, is it not fundamentally the same as lattyware's code from 2005, except storing the count in a database instead of a text file? (I'm not overly keen to learn how to manage databases at the moment as I have a lot of other stuff to learn!)
Was This Post Helpful? 0
  • +
  • -

#12 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6317
  • View blog
  • Posts: 29,984
  • Joined: 10-May 07

Re: How do I count downloads from my website ?

Posted 30 March 2016 - 04:54 PM

Minus the 1024 bytes in every load, & the header refresh.
Was This Post Helpful? 0
  • +
  • -

#13 sjgreen184  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-March 16

Re: How do I count downloads from my website ?

Posted 02 April 2016 - 01:06 PM

View Postno2pencil, on 30 March 2016 - 04:54 PM, said:

Minus the 1024 bytes in every load, & the header refresh.


Thanks for that. I had a try removing those parts but whatever I did it either didn't count the actual downloads, or did the rapid iteration thing when the page was loaded. Definitely something to sort out when I have time to learn php I think! Meanwhile I will just have to make do with it as it is.

Thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1