Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Is it possible to track downloads from a website by IP address?

Ideally, I would like to see a log file with possibly time stamps, occurrences, and who (IP address, and/or country of origin).

If someone could help point me in the right direction...

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I would like to see a log file

Your server access logs contain the information, you just need to extract it.

The access logs (text file) contain a record of every request made to your server. Included in the access log is the timestamp, the URL of the file requested, the IP address that requested the file and the status code.

To sum up all the times a particular IP address has requested a particular file you will need to traverse the log file. There are numerous tools around for processing access logs, however, you can write your own if it is a specific query you require.

Just to add, if you are doing this proactively then you would probably do this in your download script... log the File, IP address and increase a counter when the download is actioned.

share|improve this answer
    
Do the server logs tell me who (IP address) downloaded what file, when, and/or how many times? How do I extract the server logs? –  Zach Sep 24 '12 at 14:11
    
Basically, yes - although you will need to manually sum up the "number of times", since each record in the access log is 1 request. I've updated my answer. –  w3d Sep 24 '12 at 14:43
    
Thanks for your informative response. Do you know of any third party software that does this? –  Zach Sep 24 '12 at 17:42
    
Most webstats software (Awstats, Webalyzer, etc. - included with many hosting packages) works by analysing the raw access logs, however, I don't know a tool off hand that will report this particular metric. I'm sure there is one. –  w3d Sep 25 '12 at 14:59
    
Thanks! This should help me get on my way! –  Zach Sep 26 '12 at 15:19

If you are looking for something more simple and more specific. You could consider using AJAX to build your own log files system (or database) containing only the downloads you want to track.

The main reason for this is : because the webserver access logs contains eeeeeevery request made to your webserver. That means when a user only open one of your site's page, it can add an (extremely approximate) average of 30 to 70 lines in your log file. One for every little things used in the page (from HTML/CSS/JS files to every little beautiful 16x16px icons you've made with a lot of love using paint)

So if you want to track only specific files (like if you have a music download site and want to track only those music files), you could add an "onclick" event listener on your download links that DON'T point to the file, instead it fires an AJAX function that will run a server side script in witch you could save the infos about the download (ip address, timestamp, referrer, browser infos, etc...) :

Option 1 : in a log file if you want a simple chronological representation

Option 2 : in a database if you want to keep track of download counters more easily and in a more optimized structure as you won't duplicate data on the server.

After that "infos saving part", send back the URL of the file the user want to download to the browser and then, the browser gonna load this URL and the user gonna be able to download the file.

Using that method, you can be sure the download have been logged before the user download your file. It's better than sending the AJAX request simultaneously when a user click happen.


The only downside of this is : the fact that it's a "top layer" solution, if a user know the URL of your file and write it directly in his address bar, he will bypass your download counter. That wouldn't happen on a log files system based directly on the webserver (Apache or others).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.