Home Messages Index
[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index

Re: can have a time expired link?

  • Subject: Re: can have a time expired link?
  • From: Mitja <nun@example.com>
  • Date: Wed, 08 Jun 2005 19:08:24 +0200
  • Newsgroups: alt.html
  • Organization: Slovenija OnLine - SiOL
  • References: <R6Dpe.16869$iy2.6561@newsfe1-gui.ntli.net> <1118243532.a8f23e21662617f4818d6eb87cf9375d@teranews> <d8727n$ekh$1@godfrey.mcc.ac.uk> <op.sr14670edob4us@ibis> <d874hc$fck$1@godfrey.mcc.ac.uk>
  • User-agent: Opera M2/8.0 (Win32, build 7561)
  • Xref: news.mcc.ac.uk alt.html:288971
On Wed, 08 Jun 2005 17:57:29 +0200, Roy Schestowitz <newsgroups@schestowitz.com> wrote:

Mitja wrote:

On Wed, 08 Jun 2005 17:18:12 +0200, Roy Schestowitz
<newsgroups@schestowitz.com> wrote:

Martin Magnusson wrote:

diablo wrote:
I want to offer a download to people for a certain amount of time -
after the link expires.

I don't believe that's possible using only HTML. You would have to remove the file manually or have a server-side script to automate it.

Set up a cron job for the day of expiry, say: 20 22 24 * * cp ~/index2.html ~/index.html; rm ~/index2.html

Which is still a server side script, although admittedly not one that
interacts with the server. And using cron for this kind of job is at best
not overly elegant, either...

I'd go for a database (can ba plain-textfile based one) with valid/active "passwords".

That's still quite laborious. How about changing that cron job to a simple chmod command.

Hmm.... can't help, still think my way is cleaner, easier to automate and therefore less prone to errors - not to mention /less/ laborious in the long run. No manual messing with cron.tab. Just to show you such a script is not too complicated, here's an example in python (not tested, very probably has some errors):

import string
import random
import time
import sys

def makeLink():
"returns the hash from which to create the link of form getBook.py?hash=..."
hash = ''.join([random.choice(string.ascii_uppercase) for i in range(32)]);
f = open('hash.db','a')
f.write(hash+' '+`time.time()`)
return hash

def get(hash):
"when the script is called with an actual hash, call this func to check if it's a valid one"
db = dict([line.split() for line in open('hash.db')])
assert time.time()-db[hash] < 3600*24*7
sys.out.write('content-type: application/x-pdf\n\n'+open('theBook.pdf').read())
except KeyError, AssertionError:
sys.out.write('content-type: text/plain\n\nInvalid or expired hash.')

Now for a real, running script of course you'd want to fancy it up a bit, but the above few lines generally cover all of idea.

[Date Prev][Date Next][Thread Prev][Thread Next]
Author IndexDate IndexThread Index