PDA

View Full Version : Keep count on Download script?


Bengal313
01-12-2003, 06:50 AM
I am starting a download page full of zip files. I have a table that contain a pic of the content, files size, and i want to display the number of times the zip file been download. sort of like the ones you see you download a script, images, etc. How can i include that on my pages? I'm using PHP and MySQL.

Transistor
01-12-2003, 08:15 AM
Hey Shakim,
my suggestion would be:

1 serve a cookie to the user who wants to download (if you already served a cookie, never mind).

2 create a script that will serve the download, this script will also record the attempt (I have not found a safe way to know for sure when a user completed or not a download from PHP) of download to a table (the cookie name, IP, country, user agent... whatever you like).
Think of it as a "log", everytime someone clicks on the link to download (might look like download.php?id=3), a new record is added to this "download log".
Why? because I have found that it is safer to record each move individually and then analize them, than relaying on a counter, because, you never know what is going on.
You could get nice info, like countries, user agents, IPs, etc, like "This file has been downloaded X times, from .com, .us, .mx, .uk"

3 Your choice:
a) dynamically (every time a user requests your downloads page) read the "download log" table to count downloads, etc.
b) run a PHP file every X hours/days/months to make a static page with the download statistics from your "download log".

I guess that depends pretty much on your server load and bandwitdth used by your users downloading stuff.

How do you like that?
Would you like more help? I'll be happy to.
Hope you find this userful.