Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6350057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:44:21+00:00 2026-05-24T21:44:21+00:00

I have a website where users should be able to log in and listen

  • 0

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 the file should reside on the server (not be stored in the MySQL database), but not be able to be accessed by non-users who have the path to the URL.

For example: say my mp3 is located at mysite.com/members/song.mp3 If you are logged in, you should be able to see the mysite.com/members/index.php page, which will allow access to the song.mp3 file. If you’re not logged in, the mysite.com/members/index.php page will not show you the song.mp3 file, and linking directly to it should not grant access.

I’m pretty sure this is done via htaccess, and I have done a lot of Googling already, and searched on here. The two closest answers I found were this htaccess guide http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/ and this StackOverflow question Block direct access to a file over http but allow php script access but neither answer all my questions to meet my criteria. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:44:23+00:00Added an answer on May 24, 2026 at 9:44 pm

    Into folder members create new folder files, move here all your songs, create new .htaccess file and add the following lines:

    Order Deny,Allow
    Deny from all
    

    Into folder members create file get_song.php and add the following code:

    if( !empty( $_GET['name'] ) )
    {
      // check if user is logged    
      if( is_logged() )
      {
        $song_name = preg_replace( '#[^-\w]#', '', $_GET['name'] );
        $song_file = "{$_SERVER['DOCUMENT_ROOT']}/members/files/{$song_name}.mp3";
        if( file_exists( $song_file ) )
        {
          header( 'Cache-Control: public' );
          header( 'Content-Description: File Transfer' );
          header( "Content-Disposition: attachment; filename={$song_file}" );
          header( 'Content-Type: application/mp3' );
          header( 'Content-Transfer-Encoding: binary' );
          readfile( $song_file );
          exit;
        }
      }
    }
    die( "ERROR: invalid song or you don't have permissions to download it." );
    

    And now, you can use this URL to get the song file:
    http://mysite.com/members/get_song.php?name=my-song-name

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an administration website - the users of which should be able to
I have a internal website that users log into. This data is saved as
I have created a website that works with different sessions and every users has
I have a website where users can upload their files; these are stored on
Say you have a website for users to search for hotel rooms for rent.
We have developed our website(Business users website) in .net Framework 2.0 Our client us
We have a simple registration form for our website users where we only require
The situation is, I have a website where the users get a sub domain.
I have a website form that collects url of users to store in a
I have a website that prompt the users to enter serial number for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.