luckr
luckr

Reputation: 73

Deny Access to Music Files URL

I have a folder called music in the root of my website, and there is some music in it.

I got a script to create a music player and I'm getting the music from that folder:

<li><a href="music/jp.mp3">John Park</a></li>
<li><a href="music/oor.mp3">OOR</a></li>

And it is working pretty well but the problem is that people can access the music by entering the url, example:

http://localhost/musicplayer/music/jp.mp3

And if you access it from the url there is an option to download it.

So I made some research and I created a .htaccess file in the folder "music" and I have putted the code DENY FROM ALL.

And it worked people couldn't access to the mp3 url's, but now the script of music player can't run the music aswell.

So is there any fix for this problem, I would love it!

Summary: Forbid people to access url of the music but the script still get the musics.

Upvotes: 0

Views: 129

Answers (1)

Dan Hastings
Dan Hastings

Reputation: 3280

You will need to hide the mp3 files inside of a php script and use an apache rewrite rule to hide this.

RewriteRule ^musicplayer/music/jp\.php$ /musicplayer/music/jp.mp3 [L]

The above rule will make the end user think that they are viewing the mp3 file, but its actually a php script. Inside this script, you can then put some logic to determine whether you want to let the user view the file or not.

if(validrequest)
{
//output mp3
}
else
{
//invalid permissions
}

Upvotes: 1

Related Questions