Jump to content

Disable Direct Download


ZulfadlyAshBurn

Recommended Posts

I am creating a music player for my school and it is only available online. It is used to stream music produced by students. I would like to disable direct download from the servers. The best i did was to base code and store session but they are still able to download how to disallow them from downloading

 

index.php

<?php

$nameofdir = "music/";
$domain = $_SERVER['HTTP_HOST'];
$dir = opendir($nameofdir);
$unique = base64_encode(uniqid());
$_SESSION["uid"] = "$unique";
while (($file = readdir($dir)) !== false)
  {	
if (strpos($file, '.mp3') !== false) {
   	$name = str_replace('.mp3', ' ', $file);
   	$files = str_replace(" ", "%20", $file);
$id = base64_encode($file);
?>
<li><a class="media" href="getaudio.php?uid='<?php echo $unique; ?>'&id='<?php echo $id; ?>"><?php echo $name; ?></a></li>

 

getaudio.php

<?php 
header("Content-type: audio/mp3"); //mp3 contenttype 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
session_start();
$id = base64_decode($_SESSION["uid"]);
$uid = base64_decode($_REQUEST["uid"]);
$url_id = base64_decode($_REQUEST["id"]);
if ( $id == $uid ) {
header("Location: music/" .$url_id);
}
else {
echo "Thank you for trying to download.";
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/240018-disable-direct-download/
Share on other sites

There is no way to prevent a direct download. Best you can do is make it relatively difficult (though it's still fairly easy if you know how to get around it) and that requires hiding the URL - typically by using a Flash or Java player embedded in the page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.