Simple way to Track Downloads

A simple google search of “download tracker” yields 92,900,000 results. There are also a lot of nice download tracking script that i know. They all come in useful when you have a lot of files for download and you have your own download repository of large number of files, like on my other Free Webmaster Resources website (though i use a custom coded one there). But on this blog, i just have some 2-3 themes and 1 plugin for download as of now. So, a download tracker would simple be unnecessary. But, i would like to track how many times my file have been downloaded. I use a simple method here on my blog.

I have a PHP file with the following code :

<?php
$hits = file_get_contents("SOME-NAME.txt");
$hits = $hits + 1;
$handle = fopen("SOME-NAME.txt", "w");
fwrite($handle, $hits);
fclose($handle);
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=LINK-TO-ORIGINAL-ZIP-FILE" />';
?>

The SOME-NAME.txt is the text file to which the number of downloads is written. It needs to be CHMODed to 777. And initially, it should contain “0″ as the file content. The LINK-TO-ORIGINAL-ZIP-FILE is the link to the file that needs to be downloaded. It can be any type, not necessarily be a Zip file.

I currently use this method for all my downloads on this blog. For eg, Got Banners can be downloaded from Here. The tracking is done on this TEXT File. Now, i hope that helped some of you.

30 Responses

Nice tip . Will definately help me sometime .

Nice Tip , will definately come in handy sometime .

Thanks. This could definitely be very useful in the future.

Cool ! Thanks for your comments :D

MDB

PHP…. just thinking about it sends shivers down my spine… but its easy when someone gives you the code. Thanks.

Yep, its has once upon a time sent shivers down my spine too. But, i got used to PHP and became a 50% expert in it.

Thanks to SimpleMachines forum software. It gave me experience. Thanks to PHP Freaks and their forum members. Without them i could not have imagined about PHP. Clever Tutorials and Kontactr and another video indexing site – all these i made only with the help of PHP Freaks.

Thanks for the code, and also for the recommendation for the PHP freaks forum!

Man this is awesome.
Simple and useful at the same time!

Thumbs UP!

sim

To my mind it must be mentioned about such parameters as “safe_mode”, “safe_mode_gid”, “safe_mode_include_gid”, “open_basedir”. These parameters are set in “php.ini” and they limit of using “fopen” and “fwrite”.

You can use simple Mysql queries as well to store the counter in database instead of a text file

Yes that is possible.. Just that this method doesn’t use a database and so it is simpler…

Thanks for the code, and also for the recommendation for the PHP freaks forum!

There are a lot of WordPress plugins that have the same purpose, but nice coding skills!

found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later ..

Thanks for those scripts. An easy way to monitor youre files.Though I’m not yet familiar with PHP language. But sooner or later I could use those scripts of yours.

affiliate.solutions

You have sparked some of my interest and I am going to do some additional research. Feel free to check out some my blog in the near future… as I just posted a great blog about the 36 Best WordPress plugins for 2009. thanks

This is a good tracking strategy.