Hide full MP3 file

I have a music player that references a song using the following syntax:

<li><a href="" data-src="http://s3.amazonaws.com/audiojs/02-juicy-r.mp3">title</a></li> 

Is there any way to perform this operation on the server side, and then display as (see below) for the user?

During the search, I came across this ... I like the idea of ​​having an external data file ... for example:

 <?php // get-file.php // call with: http://yoururl.com/path/get-file.php?id=1 $id = (isset($_GET["id"])) ? strval($_GET["id"]) : "1"; // lookup $url[1] = 'link.mp3'; $url[2] = 'link2.mp3'; header("Location: $url[$id]"); exit; ?> 

then using http://yoururl.com/path/get-file.php?id=1 as a link ... the only problem is when typing http://yoururl.com/path/get-file. php? id = 1, the user goes directly to the file ... is there a way to disable this ability ... maybe some code on get-file.php itself?

+4
source share
5 answers

So, I made a combination of things that suit me ... although not entirely safe, it definitely helped me obscure this a bit.

First of all, I use AudioJS player to play music, which can be found at: http://kolber.github.com/audiojs/

Basically what I did was:

  1. Instead of using "data-src" as the path to my songs, I called it the "key" so that people do not always think that this is the way.
  2. Instead of using "my-song-title" as the name of the songs, I changed it to a number like 7364920 so that people could not search for it in the source and thus find the URL.
  3. I added + “mp3” to the javascript code after all the “key” variables, so I would not have to declare it in a private link.
  4. I used a relative path like "./8273019283/" instead of "your-domain.com/8273019283/", so it would be harder to say that I am displaying a URL.
  5. Added a link to iTunes in href so that people couldn’t understand how I pulled out the file.

So now my inline JavaScript looks like this:

 <script type="text/javascript"> $(function() { // Play entire album var a = audiojs.createAll({ trackEnded: function() { var next = $("ul li.playing").next(); if (!next.length) next = $("ul li").first(); next.addClass("playing").siblings().removeClass("playing"); audio.load($("a", next).attr("key") + "mp3"); audio.play(); } }); // Load the first song var audio = a[0]; first = $("ul a").attr("key") + "mp3"; $("ul li").first().addClass("playing"); audio.load(first); // Load when clicked $("ul li").click(function(e) { e.preventDefault(); $(this).addClass("playing").siblings().removeClass("playing"); audio.load($('a', this).attr('key') + "mp3"); audio.play(); }); }); </script> 

My link looks like this:

 <a href="<?php $link = 'http://itunes.apple.com/us/album/falling/id504779876?i=504779883&uo=4'; $obfuscatedLink = ""; for ($i=0; $i<strlen($link); $i++){ $obfuscatedLink .= "&#" . ord($link[$i]) . ";"; } echo $obfuscatedLink; ?>" target="itunes_store" key="<?php $link = './8249795872/9273847591.'; $obfuscatedLink = ""; for ($i=0; $i<strlen($link); $i++){ $obfuscatedLink .= "&#" . ord($link[$i]) . ";"; } echo $obfuscatedLink; ?>">Falling</a> 

When you download it in a browser and see the source code, you will see:

 <a href="&#104;&#116;&#116;&#112;&#58;&#47;&#47;&#105;&#116;&#117;&#110;&#101;&#115;&#46;&#97;&#112;&#112;&#108;&#101;&#46;&#99;&#111;&#109;&#47;&#117;&#115;&#47;&#97;&#108;&#98;&#117;&#109;&#47;&#102;&#97;&#108;&#108;&#105;&#110;&#103;&#47;&#105;&#100;&#53;&#48;&#52;&#55;&#55;&#57;&#56;&#55;&#54;&#63;&#105;&#61;&#53;&#48;&#52;&#55;&#55;&#57;&#56;&#56;&#51;&#38;&#117;&#111;&#61;&#52;" target="itunes_store" key="&#46;&#47;&#56;&#50;&#52;&#57;&#55;&#57;&#53;&#56;&#55;&#50;&#47;&#57;&#50;&#55;&#51;&#56;&#52;&#55;&#53;&#57;&#49;&#46;">Falling</a> 

Then, when you use Web Inspector or Firebug, you will see:

 <a href="http://itunes.apple.com/us/album/falling/id504779876?i=504779883&amp;uo=4" target="itunes_store" key="./8249795872/9273847591.">Falling</a> - *which doesn't completely give the url away 

Essentially, I made the link look like an API key. The cool thing is that you can’t just copy the link directly from the source view or directly from Web Inspector / Firebug. It is not error protected and can definitely be broken, but the user must know what he is doing. This holds most people back, but still allows the player to get the URL needed to play the song :)

* Also, I got the php obfusticate script somewhere on the Stack Exchange, I just don’t know where.

+5
source

Instead of redirecting the header, add the appropriate headers and include the audio file in your PHP code. Then, in your .htaccess file, you can deny access to the directory in which your audio files live.

+1
source

Not. This is not possible because the browser interprets HTML to make the page work correctly. Therefore, if the client (browser) does not know where the mp3 will come from, it will not be used.

On the other hand, if you want the music to switch to songs by clicking on the link, I suggest you study some tools, such as http://jplayer.org/

EDIT: the only way to possibly prevent direct access to the file itself is to read the file instead of linking to it from the script. For example, on my image hosting site http://www.tinyuploads.com/images/CVN5Qm.jpg , and if you want to see the actual path to the file on my server, the CVN5Qm.jpg file is not visible from the public_html folder. No direct access to the file. I use databases to take an image id, see where it is stored, then read the file () in a script and display the appropriate headers for the image output.

Hope this helps

0
source

If you use the amazon s3 service, you can use a signed URL for your files. It will be more secure since you must be subscribed by the user, and also the url may expire. Read this .

0
source

I use http_referer and I can control the link procedure

 <?php // key.php // call with: http://yoururl.com/path/key.php?id=1 $page_refer=$_SERVER['HTTP_REFERER']; if ($page_refer=="http://www.yourdomine.com/path/page.html") { $id = (isset($_GET["id"])) ? strval($_GET["id"]) : "1"; // lookup $url[1] = 'link1.mp3'; $url[2] = 'link2.mp3'; header("Location: $url[$id]"); exit; } else { exit; } ?> 
0
source

All Articles