The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Password Protect FILES (not dir)

Discussion in 'General Discussion' started by willstein, Apr 28, 2005.

  1. willstein

    willstein Registered

    Joined:
    Oct 24, 2003
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Sure it's possible to password protect a directory, but is there a way to password protect an individual file?
    *Without placing the file in it's own directory and passwording that.

    If cPanel can't do it, who can?
    Can I go straight into a file to do it?

    The following two files need to be passworded:
    public_html/stfapplication/use/applynow/admin/del_rec.php
    public_html/stfapplication/use/applynow/admin/del_file_rec.php
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    It's not realy anything to do with cPanel, it's how apache works and AFAIK you cannot password protect individual files. You could always implement HTTP_AUTH for php scripts, but you'll need to go read up on that on a php site.
     
  3. dgbaker

    dgbaker Well-Known Member
    PartnerNOC

    Joined:
    Sep 20, 2002
    Messages:
    2,578
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Toronto, Ontario Canada
    cPanel Access Level:
    DataCenter Provider
    Actually.... you can with .htaccess protect a file, group of files or a directory, limit methods like POST/GET. (sorry chirpy)

    Create a standard .htaccess

    Code:
    AuthUserFile .htpasswd
    AuthGroupFile /dev/null
    AuthName JustMe
    AuthType Basic
    
    Now add the following at the end
    Code:
    <Files admin.cgi>
     Require user admin
    </Files>
    
    You should now have

    Code:
    AuthUserFile .htpasswd
    AuthGroupFile /dev/null
    AuthName JustMe
    AuthType Basic
    <Files admin.cgi>
     Require user admin
    </Files>
    
    NOTE: This traverses subdirectories as well.

    To do pattern protect replace the file part with
    Code:
    <Files ~ "\.(gif|jpe?g|png)$">
     Require user admin
    </Files>
    
     
    #3 dgbaker, Apr 28, 2005
    Last edited: Apr 28, 2005
  4. dalem

    dalem Well-Known Member
    PartnerNOC

    Joined:
    Oct 24, 2003
    Messages:
    2,577
    Likes Received:
    40
    Trophy Points:
    48
    Location:
    SLC
    cPanel Access Level:
    DataCenter Provider
    and another with .htaccess

    <FilesMatch file.htm>
    AuthName "Restricted File"
    AuthType Basic
    AuthUserFile /home/usename/.htpasswd
    require valid-user
    </FilesMatch>

    <FilesMatch file2.htm>
    AuthName "Restricted File"
    AuthType Basic
    AuthUserFile /home/username/.htpasswd
    require valid-user
    </FilesMatch>

    and so on
     
  5. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Live and learn - That's great :)
     
  6. willstein

    willstein Registered

    Joined:
    Oct 24, 2003
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    thanks - ill try it out and let you know.
     
  7. bela flor

    bela flor Member

    Joined:
    May 26, 2005
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Is there a way to allow files on that website to call protected files or directories that are password protected?

    What I am doing is trying to call a js script, but I do not want others to see the scripting. So I placed it in a directory and then password protected it. I only need files with in my site to be able to call this js script, but I do not want it were they have to enter the username and password to view that file. So I have a web page that is http://www.mydomain.com/test.html and inside of that page it calles a js file that is located at http://www.mydomain.com/scripts/test.js. The script directory is password protected. So when I go to http://www.mydomain.com/test.hmtl it is now asking me for the username and password for the scripts directory. Is there a way to make it were any file that is coming from http://www.mydomain.com will not have to enter the username and password.

    Thanks,

    Bela
     
Loading...

Share This Page