in reply to Ideas for implementing download links that expire, via e-mails

That's overly complicated. Just include the timestamp the link expires on plus a hash code based on the timestamp, like follows:
use strict; use warnings; my ($url, $key, $exp, $hash, $link); $url = 'http://www.domain.com/folder/page.html'; $key = 'm239VdSn'; $exp = time() + 60*60*24; $hash = crypt(substr($exp,-8,8),$key); $hash = substr($hash, 2); $hash =~ s/[^a-zA-Z0-9]//g; $hash = uc($hash); $link = "$url?$exp-$hash"; print $link;
Note that crypt only works on the first 8 characters of the given text, so you want to feed it the last 8 characters of the timestamp. The modifications to the resulting hash were to make the link look prettier.

EDIT: Added a line to remove the first two characters of the hash, which when using crypt, contain the salt.

  • Comment on Re: Ideas for implementing download links that expire, via e-mails
  • Download Code

Replies are listed 'Best First'.
Re^2: Ideas for implementing download links that expire, via e-mails
by Fletch (Bishop) on Apr 22, 2005 at 14:49 UTC
    $hash =~ s/[^a-zA-Z0-9]//g;

    ITYM $hash =~ y/a-zA-Z0-9//cd; HTH. HAND.

    $ perl -MBenchmark=cmpthese -le 'cmpthese( 500_000, { s => sub { $_ = +q{123#$%abc^&*DEF}; s/[^a-zA-Z0-9]//g }, y => sub { $_ = q{123#$%abc^ +&*DEF}; y/a-zA-Z0-9//cd; } } )' Rate s y s 174825/s -- -80% y 862069/s 393% --