I'd do something similar to what TedPride suggests (I agree that there's no need to involve a DBMS in this), except that I'd make a subroutine for the purpose of computing $hash, since the code will need this computation at least at two different places in the program: 1) to create the $hash, and 2) to test that the $hash and $exp parts of a requested URL match. Also, instead of having $url point to a regular HTML page, I'd make it point to a CGI script that served the page if requested before the URL-encoded expiration date.

Alternatively, you could devise a simple encoding/decoding scheme to encrypt or at least obfuscate the expiration time. Here's one.

Untested:

package My_Enc_Dec; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK; { my $passphrase; BEGIN { $passphrase = 'choose something better'; } use Crypt::RC4; use MIME::Base64; push @EXPORT_OK, 'enc'; sub enc { ( my $ret = encode_base64( RC4( $passphrase, shift ))) =~ s/==\n$/ +/; return $ret; } push @EXPORT_OK, 'dec'; sub dec { return RC4( $passphrase, decode_base64( shift )); } } 1; __END__ # ............................................................ # link-generating code use strict; use warnings; use My_Enc_Dec 'enc'; my $url = 'http://www.domain.com/cgi-bin/fetch.pl'; my $exp = enc( time + 60*60*24 ); my $link = "$url?$exp"; # ............................................................ #!perl # fetch.pl use strict; use warnings; use CGI; use My_Enc_Dec 'dec'; my $exp = dec( param( 'keywords' ) ); time <= $exp or have_a_cow();

Update: Added import/export paraphernalia.

This particular encoding/decoding scheme is not necessarily the best (on the one hand, it may be overkill as far as obfuscating the expiration time goes, and on the other, you may be able to find a enc/dec module in CPAN that provides both adequate encryption/obfuscation and nice alphanumeric output in one swoop), but it gives you an idea of a general approach.

the lowliest monk


In reply to Re: Ideas for implementing download links that expire, via e-mails by tlm
in thread Ideas for implementing download links that expire, via e-mails by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.