dss087358 2014-10-09 22:48
浏览 139

如何限制对目录的访问,以便我可以从浏览器运行php脚本

First post, be gentle :) ... I have been doing searches on this site as well as others and realize I may be in over my head.

Here is the situation:

1) I have a website running on BlueHost (linux OS, I think is running Apache) that is open for general access

2) I have a set of php scripts on the website that I would like to limit the access to only one user via some sort of login through a webbrowser.

3) I have put the scripts in a directory under /home/public_html. I did not know how to access the files with a web browser above that level (like in /home)

4) These scripts do not access any other part of the website nor does any other part of the website access the scripts.

Here is what I tried:

1) Using cpanel to change the permissions on the directory. Result was a 404 when I try to access the scripts with a browser.

2) .htaccess/.htpasswd for the folder in question (found some instructions here and on the web). Didn't seem to force asking for a password so I probably did something wrong

I know this is vague but I will ask it anyway... Given my situation, is there a preferred approach I can research? For example, having the php code ask the user for a password, somehow accessing the scripts from the server side, etc.

Thanks for your patience and help

  • 写回答

3条回答 默认 最新

  • dtvpl739577 2014-10-09 23:27
    关注

    Do the following in the folder where the php scripts reside,

    1. Create a .htaccess file in your text editor. Add the following data and save the file as .htaccess. The leading dot is important.

    AuthUserFile /path/to/.htpasswd AuthType Basic AuthName "My Secret Files" Require valid-user

    1. Edit the path/to/.htpasswd to match the folder where your php scripts reside. You can also make the AuthName anything you want. This is the name the user sees when the password prompt appears.

    2. Copy that file to the folder where your php scripts reside.

    3. Now create the actual password file. The format looks like this:

      username:encryptedPassword

    4. You can create a username/encrypted pair by using the free tool here:

      http://www.web2generators.com/apache/htpasswd_generator

    Just enter the username and the unencrypted password you want to assign the user. You may also want to assign yourself one so you can also access the files from your browser.

    There are other ways to create the username and password, but this will get you up and running. You can always Google how to do it from cpanel and the command line if you prefer.

    1. Click the generate link and copy the resulting code.

    2. Open a new file in your text editor and paste the results.

    3. Save it as .htpasswd

    4. Copy that file to the folder where your php scripts and the .htaccess file reside.

    5. Access the php script from your browser. You should be prompted to enter a user name and password before the script will execute.

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题