Customizing SMF > SMF Coding Discussion
Temporary Download Link Generator
(1/1)
MiY4Gi:
Is there a mod that can take a download link, and create temporary download links for users so that nobody sees the true download URL?
I want to prevent hotlinking of my download links, so I want SMF or my server to hide the true link, and only give temporary links to users that expire after a time.
I preferably want BBCode (something like [ddl] [/ddl] that I can wrap around links to cause SMF to execute the above mod/code on those links.
Is there a mod that does this, and if not, how do I go about coding this into SMF. I'll be using SMF 2.0.2.
Here's some code that could maybe help you: http://www.tutorialchip.com/php-download-file-script/
Here's an example of that code in action: http://www.tutorialchip.com/php-download-file-script/?c=demo
Sorck:
Is this intended to stop just guests from downloading hotlinked files? If it's purely to stop guests then could you not just disable guests from accessing attachments? Or are these files not going to be attached in that way?
If the above isn't what you require then you could upload files to your server (either via FTP/a web form) and you would then get a BBCode to link to it. You could then post that code, say [ddl]RANDOM_FILE_IDENTIFIER[/ddl] which would query the database/cache for that file identifier and then give a short life link to that resource. It might stay valid for 10 or 15 minutes and/or only valid for that user/IP/session.
I don't think, beyond the first solution, that it already exists for SMF.
Here are some basic ideas on how to do it not implementing any actual code. I might keep modding the functions. :P
--- Code: (Sorck's ideas sandbox) ---<?php
// downloads functions
function DDLMain() {
// called by SMF in index.php
// see if there's a request file, if so then URLToID() it
// if URLToID() is false then throw an error.
// else use PushFileToUser() to let the user download the file
}
function URLToID( $urlkey ) {
// if it doesn't exist in the database/is too old, return false
// if it exists then return it's id_file
}
function GetFileURL( $id_file ) {
// delete any old file URLs from the database older than a certain ACP settable time
// query the databse to see if there's a valid file signature with at least 5 or so minutes left on it (set time in ACP)
// return the existing URL if one exists, else make a new one
}
function PushFileToUser( $id_file ) {
// query the database for file info
// send the right http headers
// get the files content from the filesystem and push it to the browser
}
--- End code ---
MiY4Gi:
Thanks for your input. It isn't intended for guests, but for all users. Guests will have additional restrictions (i.e. they won't even be able to see ANY link). What you suggested looks like it might work. I had a feeling that I would have to use the database.
One thing though, I won't be hosting the files on my server. I'll be hosting the files at an external file server which has limited bandwidth, so I don't want people hotlinking or sharing the download links. Would I still be able to do it, even with the files on a different server?
How does the above code work? Does the database store the file's actual URL, then a PHP file is used to produce a temporary URL, or does the database store both the actual file's URL AND the temporary URL?
In summary, say the file is File.txt, and it's direct download link is at http://filehost.tld/File.txt, then I want to serve the file to a user at http://mysite.tld using a temporary download link (e.g. http://mysite.tld/ddl/122151).
ApplianceJunk:
I use dropbox.com to share some service manuals, pdf files.
The shared link dropbox creates for you changes if you change the name of the folder that the .pdf files are stored in.
So for example, if i have the .pdf files I share links to called, Service Manuals May 2012 and change it a month later to Service Manuals June 12 all the links I shared to them .pdf files that dropbox.com created change and the new shared links dropbox.com creates are some random thing so there is no guessing what the links changed too.
Not sure if anything like that would work for you or not, but thought I would throw it out there.
Navigation
[0] Message Index
Go to full version