Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

FYI, I used the following code and it did not work

Order deny,allow
deny from all

Any help would be appreciated

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
847 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...