•  Home
  •  Dashboard
  •  Company
    • About Us
    • Blog
    • Careers
    • Contact Us
    • Data Centers
    • Looking Glass
    • Network
    • Reseller
  •  Hosting Services
    • Infrastructure
      • iColocation
    • Compute
      • cMetal
      • cVirtual
    • Storage
      • sObject
      • sBlock
    • Networking
      • nCDN
      • nIP Transit
      • nWavelength
    • Protection
      • pBackup
      • pDDoS
  •  Solutions
    • Ecommerce
    • Finance
    • Gaming
    • Hosting
    • Management
    • Security
    • System Integrator
  •  Support
    • Community
    • Knowledge Base
    • Open A Ticket
  •  USA & Canada: 800-933-1517
  •  International: 626-549-2801
  •  Email: sales@psychz.net
  • Services
    • new-colocation-header-img
      Infrastructure
      • iColocation
    • new-compute-header-img
      Compute
      • cMetal
      • cVirtual
    • new-storage-header-img
      Storage
      • sObject
      • sBlock
    • new-networking-header-img
      Networking
      • nCDN
      • nIP Transit
      • nWavelength
    • new-protection-header-img
      Protection
      • pBackup
      • pDDoS
  • Solutions
    • Ecommerce
    • Security
    • Gaming
    • Hosting
    • Management
    • Finance
    • System Integrator
  • Dashboard

CDN URL Token Authentication

  • Home
  • Client
  • Knowledgebase
  • CDN
  • CDN Security
  • CDN URL Token Authentication

Table Of Content

Related Articles

  • Secure Token Integration For PHP (Secondary)
  • Secure Token Integration For Python (Secondary)
  • Secure Token Integration For Python
  • Secure Token Integration For PHP
  • Add Security Token
  • Security token intro
  • Add DDoS Exemption
  • Views: (718)
  • Votes: (0)
Was this article helpful?
VOTE

CDN URL Token Authentication

Publisher: Psychz Networks,  April 19,2021

The following article will help you to generate secure URLs using URL Token Authentication accessible using a token generated using a secret key. This token can be set to expire after a specified timestamp.

To generate a secure token using PHP script, you will require to create at least one token utilizing the dashboard. This will allow you to pass the security key to our backend. If you are not sure how to create the security token using our dashboard, please follow the link https://www.psychz.net/client/kb/en/add-security-token.html.

Sample security token looks like

psychz.biz/?md5=Rbp0ZArvj3m3aOQNjo75Xg&expires=1619082510

Once the security token is generated, you can use it in PHP code to create the URL token.

<?php
//$base_url = 'https://yourdomain.com'; // This is your CDN's base URL of the site, without the slash in the end
//$securityKey = 'token_security_key'; // Your security key used to create token using dashboard
//$locationpath = '/index.html'; // provide the path starting with the '/'

function securityToken( $base_url, $locationpath, $securityKey, $expires ='', $ip_addr=''){

// Set the time of expiry to one hour from the time of the creation
$expires = time() + 3600; // This parameter is optional and is up to your discretion define its expiration to the secure URL.

// If using IP validation
$ip_addr = "192.XXX.XX.XX";// Replace the IP address with the one used in the hash. This parameter is optional and is up to your discretion if you want to provide IP restrictions or not.

// Generate the token
if(!empty($expires)){

// Generate the token with expiry
$hashableBase = $securityKey.$ip_addr.$locationpath.$expires;//here $ip_addr is optional
$token = md5($hashableBase, true);
$token = base64_encode($token);
$token = strtr($token, '+/', '-_');
$token = str_replace('=', '', $token);

// Generate the URL
$url = "https://$base_url.{$locationpath}.?md5=.{$token}.&expires=.{strtotime($expires)}";
}

else{

// Generate the token without expiry
$hashableBase = $securityKey.$ip_addr.$locationpath;//here $ip_addr is optional
$token = md5($hashableBase, true);
$token = base64_encode($token);
$token = strtr($token, '+/', '-_');
$token = str_replace('=', '', $token);

// Generate the URL
$url = "https://$base_url.{$locationpath}.?md5=.{$token}";
}

return $url;
}

// Example usage:
// Returns: '/index.html?md5=IuNSzXOiYkL-LmGJcwxMQg&expires=1488672404'
echo(securityToken('https://test.b-cdn.net', '/index.html','super-secret-code','1488672404','192.128.0.0'));

// Returns: 'https://test.b-cdn.net/index.html?md5=EuS4D8fFlTrT6zO4FymvUw&expires=1488672453'
echo(securityToken('https://test.b-cdn.net', '/index.html','super-secret-code'));

?>

Was this article helpful? If yes, please click on upvote. If you still have technical queries, please write to us at support@psychz.net

Related Articles

  • Secure Token Integration For PHP (Secondary)
  • Secure Token Integration For Python (Secondary)
  • Secure Token Integration For Python
  • Secure Token Integration For PHP
  • Add Security Token
  • Security token intro
  • Add DDoS Exemption
  • Views: (718)
  • Votes: (0)
Was this article helpful?
VOTE
Copyright © 2025 Psychz Networks,
A Profuse Solutions Inc Company
Hosting Services
Infrastructure
  • iColocation
Compute
  • cMetal
  • cVirtual
Storage
  • sObject
  • sBlock
Networking
  • nCDN
  • nIP Transit
  • nWavelength
Protection
  • pBackup
  • pDDoS
Company
  • About Us
  • Blog
  • Careers
  • Contact Us
  • Data Centers
  • Looking Glass
  • Network
  • Reseller
Policies
  • Acceptable Usage Policy
  • Privacy Policy
  • Service Level Agreement
  • Terms and Conditions
Support
  • Community
  • Knowledge Base
  • Open A Ticket
Get In Touch
  • Psychz Networks,
    A Profuse Solutions Company
    611 Wilshire Blvd #300
    Los Angeles,California 90017
    USA
  • US/Canada: 800-933-1517
  • International: 626-549-2801