• 8
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

htaccess access to file by ip range

How to allow access to file only to users with ip which are in a range of ip addresses?

For example file admin.php. and range from 0.0.0.0 to 1.2.3.4.

I need configure access to only ONE file not to directory.

Just add a FilesMatch or Files directive to limit it to a specific script.

The following would block acces to all scripts ending in "admin.php" :

<FilesMatch "admin\.php$">
    Order deny,allow
    Deny from all
    Allow from 10.0.0.0/24
</FilesMatch>

The following would ONLY block admin.php :

<Files "admin.php">
    Order deny,allow
    Deny from all
    Allow from 10.0.0.0/24
</Files>

For more information refer to the apache docs on Configuration Sections.

  • 45
Reply Report

check the man page of the Allow Directive

Order Deny,Allow
Deny from all
Allow from 10.1.0.0/255.255.0.0

A partial IP address

Example:

Allow from 10.1
Allow from 10 172.20 192.168.2

The first 1 to 3 bytes of an IP address, for subnet restriction.

A network/netmask pair

Example:

Allow from 10.1.0.0/255.255.0.0

A network a.b.c.d, and a netmask w.x.y.z. For more fine-grained subnet restriction.

A network/nnn CIDR specification

Example:

Allow from 10.1.0.0/16

Similar to the previous case, except the netmask consists of nnn high-order 1 bits.

  • 26
Reply Report

You cannot match an IP range with allow, but you can emulate it with a CIDR notation:

Order allow,deny

# 0.0.0.0 - 0.255.255.255.255
Allow from 0.0.0.0/8

# 1.0.0.0 - 1.1.255.255
Allow from 1.0.0.0/15

# 1.2.0.0 - 1.2.1.255
Allow from 1.2.0.0/23

# 1.2.2.0 - 1.2.2.255
Allow from 1.2.2.0/24

# 1.2.3.0 - 1.2.3.3
Allow from 1.2.3.0/30

# 1.2.3.4
Allow from 1.2.3.4
  • 10
Reply Report

Just do this for a single IP:

<Limit GET POST>
order deny,allow
deny from all
allow from 1.2.3.4
</Limit>

If you want to do it for a range like 10.x.x.x, then do this:

<Limit GET POST> 
order allow,deny 
allow from 10
deny from all
</LIMIT>
  • 3
Reply Report

If you are using WordPress, then the Best and Simplest method is to install the plugin - LionScripts : WordPress IP Blocker from their website http://www.lionscripts.com/ip-address-blocker

Their Professional version has much more features like country blocking and IP range blocking, bulk csv uploading etc.

  • 1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions