Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stopping access to files by extension

Status
Not open for further replies.

Hokey

MIS
Oct 28, 2000
178
US
I am currently writing some php scripts will include different HTML files depending on conditions. Everything is running fine with the scripts, but I would like to block direct access to these included HTML files except when called by the PHP include() function.

I know the best way to do this is to put the files into a folder not accessable through the httpd (above the web root), but I dont want to do this to keep things simple with the Web content developer who does all of our web graphics and HTML coding.

I have looked at the AddType directive for Apache, but this does not seem to do the trick since it just sets the content type of a file.

What I would like to do is this:
If i set the extension of a HTML file to inc - welcome.inc
I dont want a browser to access it by Typing in but only access it throught the script index.php that will include() it if the conditions are met.

Is this possible?
 
I found the answer to my own question and thought that I would post it here just in case someone else could use it. The <FilesMatch> directive will do the trick.

In my case, I put the following the the httpd.conf

<FilesMatch &quot;\.(inc|cfg)$&quot;>
Order allow,deny
Allow from 172.20.152.0/255.255.255.0
Deny from all
</FilesMatch>

This stops direct access to any files on my server with the .inc or .cfg file extensions except for all computers in with an IP address 172.20.152.XXX -- the computers used for our web development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top