HTML5 - Block direct audio access

Asked

Viewed 49 times

0

I would like to protect audio files in a public apache directory. I don’t necessarily intend to download the file (I saw several tips about) and play it in the browser only for users who have active session. I’ve already changed the .htaccess not to list the directory files, but they are still accessed directly by the URL without being logged in.

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

The only trick I imagined was putting the files in the directory /home/user/audios, 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 get a second opinion.

Grateful from now on.

PS. I am using PHP.

1 answer

0

In your file .htaccess add:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.