Shrihari - Photo
Simple way to Track Downloads
September 5th, 2007
30 Comments

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 :

  1. <?php
  2. $hits = file_get_contents("SOME-NAME.txt");
  3. $hits = $hits + 1;
  4. $handle = fopen("SOME-NAME.txt", "w");
  5. fwrite($handle, $hits);
  6. fclose($handle);
  7. echo ‘<META HTTP-EQUIV=Refresh CONTENT="0; URL=LINK-TO-ORIGINAL-ZIP-FILE" />’;
  8. ?>

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 to “Simple way to Track Downloads”
Trackback URL Feed for this entry
Madhur Kapoor  -  September 19th, 2007 at 4:10 pm  -  #4

Nice tip . Will definately help me sometime .

Madhur Kapoor  -  September 19th, 2007 at 4:14 pm  -  #5

Nice Tip , will definately come in handy sometime .

Steven Snell  -  September 19th, 2007 at 10:19 pm  -  #6

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

Hari  -  September 20th, 2007 at 1:48 am  -  #7

Cool ! Thanks for your comments :D

MDB  -  September 20th, 2007 at 12:57 pm  -  #8

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

Hari  -  September 20th, 2007 at 1:16 pm  -  #9

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.

JoLynn Braley  -  September 21st, 2007 at 5:08 am  -  #13

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

Roboblob  -  April 19th, 2008 at 4:12 pm  -  #21

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

Thumbs UP!

sim  -  May 4th, 2008 at 3:18 pm  -  #22

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”.

George Lindemann Jr  -  May 24th, 2008 at 2:28 pm  -  #23

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

Hari  -  May 29th, 2008 at 3:49 am  -  #24

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

يورو 2008  -  May 29th, 2008 at 1:41 pm  -  #25

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

Rajaie AlKorani  -  July 29th, 2008 at 10:55 pm  -  #26

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

Php Fwrite  -  December 3rd, 2008 at 4:47 am  -  #27

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 ..

Shared cPanel Hosting  -  December 21st, 2008 at 3:52 pm  -  #28

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  -  February 17th, 2009 at 5:45 am  -  #29

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

ENT Doctor  -  March 21st, 2009 at 5:40 pm  -  #30

This is a good tracking strategy.

Trackbacks/Pingbacks
copyright © gotchance.com   ~   theme by me   ~   urchin tracks my blog   ~   php, mysql   ~   monetized by adsense   ~   feedburner burns my feed.   ~   contact me via kontactr
akismet catches spam for me   ~   proudly powered by wordpress   ~   rotatee rotates my ads   ~   i share this   ~   using firefox 3   ~   gmail fan   ~   i use google reader
proud indian   ~   nokia 5310 xpressmusic   ~   foobar2000   ~   i tweet   ~   i support open source   ~   get ubuntu   ~   these links are nofollow   ~   code is poetry   ~   0.493 seconds