Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function encode_token($key, $data, $aad) {
echo var_export(json_encode($aad), true);
$nonce = random_bytes(24);
return base64url_encode(
$nonce . sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(
json_encode($data),
json_encode($aad),
$nonce,
base64_decode($key)
)
);
}
$stream_url = "https://box5.gideo.video/hls/123/directorscut.m3u8";
$token = encode_token(
// Base64-encoded encryption key.
'HdEg0dJZXaamOlqQ7D8IgVbxt1d3OlVw8/BOwO/bUKM=',
array(
// Amember user ID.
"sub" => 1234,
// Current unix time.
"iat" => time(),
// User's current IP ($_GET['REMOTE_ADDR'] if no CDN or reverse proxy).
"ip" => "255.255.255.255",
// Platform (always use "web"; OTT will use a different value)
"os" => "web",
),
array(
// Stream URL.
$stream_url,
),
);
$stream_url .= '?t=' . $token;
echo $stream_url;