Skip to content

Instantly share code, notes, and snippets.

@nadeem-khan
Last active August 29, 2015 14:14
Show Gist options
  • Save nadeem-khan/566903bd15f2cf53ca6e to your computer and use it in GitHub Desktop.
Save nadeem-khan/566903bd15f2cf53ca6e to your computer and use it in GitHub Desktop.
URL Signing for HighWinds CDN in PHP

How to Implement URL Signing for HighWinds CDN in PHP:

   //the input URL example taken from https://support.highwinds.com/display/DOCS/Content+Protection 
   $URL = parse_url("http://aaa.wdd3.cdn.net/secure123/content.mp4");
   
   // parse URL to separate the host and the rest of the url string
   $uri= $URL['path'];

   // set a secret pass  
   $secret = 'abcdef123';

   // set a delay for expiration date of token
   $delay = '60';
   
   // generate epoch for expiration date
   $ttl = time() + (1 * 1 * 1 * $delay);
   
   // create url for md5 hashing
   $message = $uri . "?ttl=" . $ttl . "&pass=" . $secret;
  
   // create md5 hash of the prepared url
   $digest = md5($message);
   
   // return finalized url as per the documentation
   $token_value = "?ttl=" . $ttl . '&token=' . $digest;     

   //return or echo the value
   echo $token_value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment