Skip to content
PHP Logo

How effective are temporary URLs or token-based access controls for preventing video downloads on a website?

Temporary URLs or token-based access controls can be effective in preventing video downloads on a website by providing time-limited access to the content. By generating a unique token or URL that expires after a certain period, unauthorized users are unable to access the video file directly. This method adds an extra layer of security to prevent unauthorized downloads of the video content.

php
// Generate a temporary token for accessing the video file
$token = md5(uniqid(rand(), true));

// Set the expiration time for the token (e.g. 1 hour)
$expiration_time = time() + 3600;

// Store the token and expiration time in a database or session
$_SESSION['video_token'] = $token;
$_SESSION['video_expiration'] = $expiration_time;

// Redirect the user to the video file with the token as a query parameter
header("Location: video.mp4?token=$token");