How tho make password protected web directory for PHP sites?

Discussion in 'PHP' started by KingCobra, Nov 8, 2010.

  1. #1
    Sir,

    I have a site built in PHP-MySQL. In mysql there is a users_info table.
    In my site there is user registration and login system.

    I want to make a file download system for my users from my site, so that the unregistered user can't download that file(s). I will put download able files in a folder that connot be accessed without going through my website and login.

    I have no idea about. I think .htaccess do this job (not sure).
    PLEASE help me. How can I make this protected dir?
    PLEASE give me an example code or tutorials links.

    THANKS IN ADVANCE
     
    KingCobra, Nov 8, 2010 IP
  2. AtomicPages

    AtomicPages Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have the right idea. You can use this in your .htaccess in the protected folder:

    
    <Files *> 
    Deny from all 
    </Files>
    
    Code (markup):
    This will not allow anyone to directly access files in this folder by just typing in the URL but your php scripts will still be able to access the folder. So you can make a php script that checks if the user is logged in and if so, grab the file from this folder and download it.

    Look at example 1 here for an example of how to download a file with php: http://php.net/manual/en/function.readfile.php
     
    AtomicPages, Nov 8, 2010 IP