User Tools

Site Tools


en:feature_url_sign_part

URL Part Signature

This type of signature could be used in case of some set of files in one folder, e.g.:

/1/2/31.mp4 
/1/2/32.mp4
/1/2/33.mp4

Therefore you could generate signed URL for this part

/1/2/

and concatenate different file name without changing signature. Another case of using URL part signature : file names in one subfolder differ with some suffix , e.g.:

/1/2/3_240p.mp4
/1/2/3_360p.mp4
/1/2/3_480p.mp4

This part

/1/2/3_

could be used for generating signature.

Example of the script for signed URL generation

<?php
# link end of life , 3600 - lifetime in seconds                       
$expire = time() + 3600;        

# file in CDN  1/2/3_720p.mp4
$file_part1 = "1/2/3_"; 
$file_part2 = "720p.mp4";
$file_part1_len = length($file_part1);
$url = ",end=$expire,len=$file_part1_len/$file_part1";

# You can change speed and buffer setting in the URL,  by default settings are taken from account`s settings,
# or from domain`s settings
# http://wiki.ahcdn.com/doku.php?id=ru:feature_default_settings
#$url = ",end=$expire,len=$file_part1_len/speed=300K/buffer=5.0/$file_part1";

$domain = 'cdn.domain.com';    

$secret = 'qwerty'; # ask  CDN support about it 
$key = substr(base64_encode(md5("$secret$url", true)), 0, 22);
$key = str_replace('/', '-', $key); 
$fullurl = 'http://' . $domain . '/key=' . $key . $url$file_part2;

# You will get link like 
# $fullurl == "http://cdn.domain.com/key=9CVHszhqqsA,end=1374068216,len=6/1/2/3_720p.mp4" 
?>

You can specify list of IPs which will not be checked for URL sign ( 'keycheck_whitelist' setting ). Can be set via CDN support.

You can read here about regular URL signature: URL signature

en/feature_url_sign_part.txt · Last modified: 2020/08/05 16:53 by psv