Solved

Restricting PHP folder access to localhost and a range of IP addresses (192.168.0.*)

Posted on 2010-08-18
4
662 Views
Last Modified: 2013-11-18
Hello,

I am running PHP/Apache on Windows and I need to restrict access on one of the folders under the www folder so that only localhost and the IPs in the range 192.168.0.* can access that folder and files under it.

I tried creating a .htaccess with:

allow localhost
allow 192.168.0.1
allow 192.168.0.2
allow 192.168.0.3
...
allow 192.168.0.255

Here are the questions:
What is the syntax to specify the range of IP rather than each IP
If a user can access the file and then that IP is no longer part of the IP range the browser seems to ignore that and still pull the file from the browser cache, not a too big issue but not very dynamic...
And last, instead of a nice simple error message like "restricted access" I get the cryptic and lengthy error message bellow. How can I change that?

Internal Server Error. The server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator, admin@domain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log.
0
Comment
Question by:deve-lopez
  • 3
4 Comments
 
LVL 26

Expert Comment

by:arober11
ID: 33472944
Try:


<Directory /somFolder>
  Order Deny,Allow
  Deny from all
  Allow From 127.0.0.1 192.168.0
</Directory>

See: http://httpd.apache.org/docs/2.0/mod/mod_access.html
0
 
LVL 26

Assisted Solution

by:arober11
arober11 earned 500 total points
ID: 33472969
On the Error Message front, simply create your own No Access Error page and add the following to your httpd.conf or .htaccess:

ErrorDocument 401 /no_access.html


See: http://httpd.apache.org/docs/2.0/mod/core.html#errordocument
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 33473025
All in one:

-----------------
1) On the IP front try:

<Directory /somFolder>
  Order Deny,Allow
  Deny from all
  Allow From 127.0.0.1 192.168.0
</Directory>

See: http://httpd.apache.org/docs/2.0/mod/mod_access.html

-----------------
2) Re the Caching issue, simply add the following to the block above:

# 1 Hour
Header set Cache-control "max-age=3600, must-revalidate"


-----------------
3) On the Error Message front, simply create your own No Access Error page and add the following to your httpd.conf or .htaccess:

ErrorDocument 401 /no_access.html


See: http://httpd.apache.org/docs/2.0/mod/core.html#errordocument
0
 

Author Closing Comment

by:deve-lopez
ID: 33524502
-
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now