View Full Version : Download counter

12-16-2002, 12:46 PM
What lanquage/method do i use to make a download counter? Where can i find a free example or learn to do it myself?

12-16-2002, 03:29 PM
miva would be ok, just.

well - just about any serverside language will do the trick, sort of depends upon which languages your host supports. No point us detailing how miva would handle the job if you can only use asp or php.

First tell us which languages you can potentially use, please.

12-17-2002, 05:44 AM
Hello? Forgotten about your post possibly? Lol.. :D
Anyway peeps who come along and read this may be in need of an answer.

I'm not fluent in PHP yet so I'll stick to the ASP version.

DlFile = Request.QueryString("f")

Set conn = Server.CreateObject("Adodb.Connection")
Set rs = Server.CreateObject("Adodb.Recordset")

Function Download(TheFile)
End Function

Function CountIt(TheFile)
SqlGetCount = "SELECT DlCount FROM DownloadCounter WHERE FileName = '"&TheFile&"'"
rs.Open SqlGetCount, conn
NewCount = rs("DlCount") + 1
SqlUpdateCount = "UPDATE DownloadCounter SET DlCount = "&NewCount&" WHERE FileName = '"&TheFile&"'"
rs.Open SqlUpdateCount, conn
End Function

CountIt DlFile
Download DlFile

Just use a querystring for the file name...
<a href="download.asp?f=yourfile.zip>Download Now!</a>

If you ever want to display the count on the page at the same time as they are downloading..

Or on another page:
Set conn = Server.CreateObject("Adodb.Connection")
Set rs = Server.CreateObject("Adodb.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&Server.MapPath("YourDb.mdb")&";"
Function GetCount(TheFile)
SqlGetCount = "SELECT DlCount FROM DownloadCounter WHERE FileName = '" & TheFile & "'"
rs.Open SqlGetCount, conn
End Function

Now just call it like this..
This file has been downloaded:<%=Call GetCount "YourFile.zip"%>

12-17-2002, 01:01 PM
Sorry, i tried to post yesterday but it said the website was under maintenance...

Thanks for the code. I don't really know and ASP or PHP, or even HTML for that matter, but i am learning and i will study that snippet. I understand how to program, though, so hopefully it won't take that long to understand.

12-18-2002, 02:24 AM
ASP isn't really complex at all. If you know BASIC then you almost automatically know ASP(vbscript).

12-19-2002, 03:21 AM
Yeah, i already know quite a bit of VB, all i need is a good book on ASP and/or PHP. Gotta raid the library...