<% Filename="" Contenttype="" Token=Session("username") & "***" Username = Session("username") SQL = "SELECT p.filename FROM product p, orderhead oh, orderline ol WHERE oh.order_id=ol.order_id and ol.product_id=p.product_id and oh.status='OK' and oh.username='" & SqlEsc(Username) & "' and p.product_id='" & SqlEsc(Request.Querystring("product_id")) & "' group by p.filename UNION SELECT p2.filename FROM product p2 where p2.category='FREEBIE' and p2.product_id='" & SqlEsc(Request.Querystring("product_id")) & "'" Set RS = Conn.Execute(SQL) If RS.EOF Then Response.redirect("/") Call LogIt("download_product.asp", Request.Querystring("product_id"), "NOTALLOWED", "", "", "", "", "") Else Filename = RS("filename") MIMEType = Right(Filename, 4) select case MIMEType case ".doc" ContentType = "application/msword" case ".exe" ContentType = "application/octet-stream" case ".jpg" ContentType = "image/jpg" case ".gif" ContentType = "image/gif" case ".pdf" ContentType = "application/pdf" case ".rar" ContentType = "application/zip" case ".txt" ContentType = "plain/txt" case ".zip" ContentType = "application/zip" case else ContentType = "image/jpg" ' Default end select 'Write a token Randomize(Cbyte(Left(Right(Time(),5),2))) For i = 1 to 50 Token = Token & chr(int(rnd*25)+65) Next SQL = "DELETE FROM download_token WHERE validfrom > SYSDATE()-30 or token like '" & SqlEsc(Session("username")) & "***%';" Conn.Execute(SQL) SQL = "INSERT INTO download_token (token, filename, contenttype, validfrom) VALUES ('" & SqlEsc(Token) & "', '" & SqlEsc(Filename) & "', '" & SqlEsc(Contenttype) & "', SYSDATE());" Conn.Execute(SQL) Call LogIt("download_product.asp", Request.Querystring("product_id"), "", "", "", "", "", "") Response.redirect("download_file.php?filename=" & Server.URlEncode(Filename) & "&token=" & Token & "&ct=" & Server.URLEncode(Contenttype)) End If %>