HTML5 - Block Direct Audio Access

0

I would like to protect audio files in a public Apache directory. I do not necessarily want to download the file (I saw several tips about it) but rather play it in the browser only for users who have an active session. I have already changed the .htaccess to not list the files in the directory, but they are still accessed directly by the URL without having to be logged in.

<audio controls>
    <source src="/audios/audio.wav" type="audio/wav">
</audio>

The only game that I imagined was to put the files in the /home/user/audios directory, for example, and when the user wants to listen, copy the audio to the public folder and play it. You would also need a routine to delete the files periodically.

I wish I could have a second opinion.

Thank you in advance.

PS. I'm using PHP.

    
asked by anonymous 29.05.2017 / 08:35

1 answer

0

In your .htaccess add:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(.+.)?seusite.com/audios [NC]RewriteRule .*.(wav|mp3)$ http://www.seusite.com/erro.php [L]
    
29.05.2017 / 12:51