Follow

Generating protectserve links for a directory

 

Question: 

I am able to generate protectserve links to limit access to each file individually, but how do I limit access on folder level? I have 10 files in one directory and want to have one hashed link to access all of them. Would that be possible?

 

--

Answer: 

Yes, Here is an example php snippet that signs URLS at the directory level and allows you to use the same relative URL/signature for any objects inside the same directory. This would be the way to do HLS streaming with our Protectserve.

 

<?php

// Example URL https://username.cachefly.net/Protected/$rules/$hash/some/directory/{index.m3u8|playlist.m3u8|chunk1.ts}

// GENERATE PROTECTSERVE URL
$secret = 'XXXXXXXXXXXXXXXXXXXXXX';
$path_to_hash = 'some/directory/'; // WHAT WE WANT TO HASH (FULL FILE PATH OR DIRECTORY)
$filename = 'index.m3u8'; // SET THE REST OF PATH OUTSIDE OF THE WHAT WE ARE HASHING
$expiretime = time() + 600000;
$rules = 'expiretime=' . $expiretime . ';' . 'dirmatch=true'; // THE DIRMATCH RULE IS WHAT ENABLES DIRECTORY HASHING
$hash = hash_hmac('sha256',$rules . $path_to_hash, $secret, FALSE);
$request = "/$rules/$hash/" . $path_to_hash;
if ($filename != '') {
$request = $request . $filename;
}
echo "https://username.cachefly.net/Protected" . $request . "\r\n";
?>

 

--

0 Comments

Article is closed for comments.