我有一个继承(包括)另一个PHP文件的PHP文件。所有继承的文件都位于名为包括一个文件夹。我希望能够限制任何直接访问此文件夹。在服务器中只有PHP文件可以用文件中的包括文件夹进行通信。我怎么可以用.htaccess实现这样的目标?
I have a php file that inherits (includes) another PHP files. All inherited files are located in one folder called "includes". I want to be able to restrict any direct access to this folder. Only PHP files within the server can communicate with the files in the "includes" folder. How can I use .htaccess to accomplish such goal?
仅供参考,我用下面的code和它没有工作
FYI, I used the following code and it did not work
Order deny,allow
deny from all
任何帮助将AP preciated
Any help would be appreciated
如果你没有实际移动选项包括文档根区域以外的文件夹,并使用include_path中(即你可以不得到它来自网络),然后输入
If you don't have the option of actually moving the "includes" folder outside of the Document Root area, and using the include_path (i.e. you can't get to it from web), then enter
deny from all
在该目录中的.htaccess目录。
in a .htaccess directory in that directory.
但是,备选方案是使用一个定义指令,只允许访问那些包括由特定授权的文件的程序。例如,将
However, alternative is to use a DEFINES directive to only allow access to those include programs by specific authorised files. For example, put
<?php defined('ACCESS_ALLOWED') or die('Restricted Access'); ?>
在包含文件的顶部,然后把
in the top of the include files, and then put
<?php define('ACCESS_ALLOWED', 1); ?>
在被允许包括这些文件中的程序。
in the programs that are allowed to include those files.
这将prevent休闲GET来这些包括运行它们的文件,并适用于任何Web服务器,而不仅仅是那些支持htaccess的文件。
This will prevent casual GETs to those include files from running them, and will work for any web server, not just those supporting htaccess files.