Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    Default Password Protect FILES (not dir)

    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. #2
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,495

    Default

    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.
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

  3. #3
    Moderator cPanel Partner NOC Badge dgbaker's Avatar
    Join Date
    Sep 2002
    Location
    Toronto, Ontario Canada
    Posts
    2,773

    Default

    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>
    Last edited by dgbaker; 04-28-2005 at 06:25 PM.
    Regards,
    David
    Forum Moderator

  4. #4
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Oct 2003
    Posts
    1,931

    Default

    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. #5
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,495

    Default

    Live and learn - That's great
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    Default

    thanks - ill try it out and let you know.

  7. #7
    Member
    Join Date
    May 2005
    Posts
    9

    Default

    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

Similar Threads & Tags
Similar threads

  1. Password Protect Dir Not working (404 Not Found 1)
    By coastg in forum New User Questions
    Replies: 0
    Last Post: 11-14-2010, 10:26 PM
  2. Password Protect and playing mp3 files
    By jryce in forum New User Questions
    Replies: 5
    Last Post: 04-08-2010, 11:36 AM
  3. Password Protect Directories: Media Files
    By dgriff80 in forum Security
    Replies: 2
    Last Post: 12-28-2007, 09:19 AM
  4. password protected sub-dir, but root dir prompt for password
    By phytonet in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 01-30-2005, 12:21 PM
  5. password protect and index protect users root www directory
    By cyberspirit in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 09-04-2003, 01:16 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube