•  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

Secure Token Integration For PHP (Secondary)

  • Home
  • Client
  • Knowledgebase
  • CDN
  • CDN Security
  • Secure Token Integration For PHP (Secondary)

Table Of Content

Related Articles

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

Secure Token Integration For PHP (Secondary)

Publisher: Psychz Networks,  August 23,2021

The following article will help you to integrate secure token (Secondary) generated using a secret key in your PHP code. First, you need to login to the dashboard and enable Secure Token option for the desired location (domain). Once you enable Secure Token option, you can create a 'Secret Key' which will be then passed on to our backend. With this, you can generate your own tokens with md5 using the PHP script below. The newly generated URL then will hold all the necessary information which will match the Secure key saved at our backend and will allow access to the user.

In secondary secure token, in secure url generated uses file name, expiry time(optional), compared to IP and expiry time and not the file name in Primary method.

Sample security token looks like

http://domain.com/TimeID/HashID/FileName

Once the security token is generated, you can use it in Python 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 '/'
//$fileName = '/abc.jpg'; // provide the file name

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

// 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.

// Generate the token
if(!empty($expires))
{
// Generate the token with expiry
$hashableBase = $securityKey.$locationpath.$expires;
$token = md5($hashableBase, true);
$token = strtr($token, '+/', '-_');
$token = str_replace('=', '', $token);

// Generate the URL
$url = "https://$base_url{$locationpath}/{$token}/{$fileName}";
}
else{

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

// Generate the URL
$url = "https://$base_url{$locationpath}/{$token}/{$fileName}";
}
return $url;
}

// Example usage:
// Returns: ' https://test.youdomain.com/index.html/AuiVJT4fw7frGmPDPuCzAg/abc.jpg'
echo(securityToken(' https://test.youdomain.com', '/index.html','super-secret-code','31536000','file-name'));
// Returns: ' https://test.youdomain.com/index.html/AuiVJT4fw7frGmPDPuCzAg/abc.jpg'
echo(securityToken(' https://test.youdomain.com', '/index.html','super-secret-code','','file-name'));

?>

Related Articles

  • Secure Token Integration For Python (Secondary)
  • Secure Token Integration For Python
  • Secure Token Integration For PHP
  • CDN URL Token Authentication
  • Add Security Token
  • Security token intro
  • Add DDoS Exemption
  • Views: (1105)
  • 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