Skip to content

Instantly share code, notes, and snippets.

@Arifursdev
Last active April 30, 2025 06:55
Show Gist options
  • Save Arifursdev/eaa910da3dc46d18eff9ef9cd86d2f21 to your computer and use it in GitHub Desktop.
Save Arifursdev/eaa910da3dc46d18eff9ef9cd86d2f21 to your computer and use it in GitHub Desktop.
BunnyCDN Embed View Token Authentication in PHP
<?php
/**
* Get BunnyCDN signed stream embed URL
*
* @return string
*/
function get_bunnycdn_stream_embed_url( $video_id ) {
$security_key = 'ENTER_YOUR_TOKEN_AUTHENTICATION_KEY';
$video_library_id = '12345'; // Replace with your actual video library ID
$expires = time() + DAY_IN_SECONDS;
$hashableBase = $security_key . $video_id . $expires;
$token = hash('sha256', $hashableBase);
$signedUrl = add_query_arg(
[
'token' => $token,
'expires' => $expires,
'autoplay' => 'true',
'loop' => 'false',
],
"https://iframe.mediadelivery.net/embed/{$video_library_id}/{$video_id}"
);
return $signedUrl;
}
// get_stream_embed_url( '7731f6ed-412d-4009-89cc-12dfd345f6b7' );
// returns https://iframe.mediadelivery.net/embed/12345/7731f6ed-412d-4009-89cc-12dfd345f?6b7?token=5f4dcc3b5aa765d61d8327deb882cf99&expires=1699999999&autoplay=true&loop=false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment