Forum Moderators: buckworks

Message Too Old, No Replies

How to create temporary links

for downloadable items?

         

nervo

7:18 pm on May 17, 2007 (gmt 0)

10+ Year Member



I'm not sure if this is the right place for this question, sorry if it's not..

I started selling ebooks and I'd need a way to send my buyers to a temporary location on the server where they can download files they purchased. That link would then expire in certain period of time.

Can anyone recommend a solution to this?
Thanks all!

piatkow

10:31 pm on May 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you depending on vanilla html and javascript or do you have server side processing and a database available?

rocknbil

7:01 am on May 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One way would be to simply point the url to a delivery script, and store the parameter in a database.

After a successful purchase, store some form of unique but identifiable URL-ending:

insert into purchases (expire_date,download_link) values (date_add(now(), interval 24 hour),'john_t_doe@wherever.com');

(The date_add above is set for now plus 24 hours, it can be any valid datetime expression.)

You then provide the custmer with their download link, built from the database entry:

http://www.example.com/cgi-bin/somescript.cgi?d=john_t_doe@wherever.com

When somescript.cgi is called it looks up the entry in the database, if it exists, open the file from a secret location and print it to the browser. The actual location of the file is never revealed. If the entry doesn't exist, it's expired and display your favorite too bad, so sad message.

A cron job would come along every hour or so and delete entries where expire_date <= now().

You could be even more slick about it with some mod_rewrite and make the URL

http://www.example.com/john_t_doe@wherever.com

Morgenhund

10:10 am on May 18, 2007 (gmt 0)

10+ Year Member



You may also store your e-books in a directory that is only accessible by your script, and not directly via web: this will prevent accidentally "leaking" your e-books storage location: place a .htaccess with the following content (say, your e-books have .pdf extension):

<Files *.pdf>
Order Deny, Allow
Deny from All
</Files>

nervo

6:23 pm on May 18, 2007 (gmt 0)

10+ Year Member



Thanks for replies guys!

piatkow-- I have server side processing and a database available but I'm not sure how to do it...

rocknbil-- your advice is too much for me. What would be the actual delivery script? I'm afraid I'd need more info to get started with this..

Morgenhund-- great advice for preventing leakage

rocknbil

6:29 pm on May 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The methods I mentioned would be pretty easy for any programmer to implement, but yeah you'd need someone adept at perl, php, or some other server-side language to set this up for you.