in reply to Ideas for implementing download links that expire, via e-mails
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.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;
EDIT: Added a line to remove the first two characters of the hash, which when using crypt, contain the salt.
|
|---|
| 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 |