PHP: How can I block direct URL access to a file, but still allow it to be downloaded by logged in users?

后端 未结 3 1563
囚心锁ツ
囚心锁ツ 2020-11-28 19:22

I have a website where users should be able to log in and listen to a song (a self-created mp3). I want to make it so the logged in user can listen/download/whatever, and t

3条回答
  •  再見小時候
    2020-11-28 19:48

    Are you using a scripting language such as PHP to handle your website? if so then the best way is to create a script that handles "delivery" of the content. Save the content in a protected directory, ie above your http or www folder. Then when the user is logged in, the link to your content would look like this:

    http://yoursite.com/listen.php?song_id=xxx

    the script will locate the required song by the id and then present the data to the user

提交回复
热议问题