PHP CDN Site Hash Generation Script

Plain HTML / Printer friendly.Plain HTML / Printer friendly.

Example script in PHP to generate the URI hash...

 

# unixdate generation sample:
$expires_y = '2010';
$expires_m = '12';
$expires_d = '11';
$expires = mktime(0 , 0 , 0 , $expires_m , $expires_d , $expires_y); 
# this therefore expires at 2010 Dec 11th, at 00:00:00

$arr_str_from   = array("+" , "/");
$arr_str_to     = array("-" , "_");
$keystr = "$url$secret_key";
# or $keystr = "$expires$url$secret_key"; # if using expiry. note that $expires is unixdate
$hashkey = str_replace($arr_str_from , $arr_str_to , base64_encode(md5($keystr , TRUE)));