3

I am making an online streaming website where users can listen to audio or video files. Currently I am calling an mp3 file in an audio tag using below code.

<a href="www.domain.com/path-to-audio/file.mp3">Play</a>

In my website a user can stream a song but cannot download it. DOWNLOADS ARE PAID. Above code is the worst thing to stream an audio file because when a user copies and pastes the above link on his browser, the song will be downloaded.

How can I securely stream the file without URL download option(user cannot copy the song url and download it).

I am using CodeIgniter(PHP framework), so how can I restrict a user to download the file directly.

DCoder
  • 12,962
  • 4
  • 40
  • 62
SunnyD
  • 71
  • 2
  • 10
  • check [this](http://stackoverflow.com/questions/6040625/play-audio-file-without-downloading-it) question on Stackoverflow. – HemChe Mar 15 '13 at 10:42
  • 1
    Something actually relevant; http://stackoverflow.com/questions/11486191/php-stream-mp3-file / http://stackoverflow.com/questions/3408927/how-do-i-prevent-direct-access-download-to-mp3-wav-files-while-allowing-a-flash – Alex K. Mar 15 '13 at 10:51

2 Answers2

1

You can use some .htaccess to direct all download requests to your PHP Script and not call the real files. Then your script can validate if the user is logged in, only then it will issue a download response. Otherwise even if someone gets the url it won't work for them because the request goes to your PHP Script and file itself is not served automatically

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • So you mean to say that instead of direct file link, I redirect it to a PHP page, where it will retrive the songs actual path and send it back? – SunnyD Mar 15 '13 at 10:49
  • I had same question using htaccess is ok, but when the files are stored in CDN then hows the htaccess will function? – Niraj Chauhan Mar 15 '13 at 10:50
0

Take a look at this Create temporary URLs. You can do similar for your domain as well.

Waqar Alamgir
  • 9,828
  • 4
  • 30
  • 36