PHP - how to make a page visible only on the local network

Hi, I have one more question: I am writing a simple website in PHP and I have a problem with the visibility of my website on the local network to make it visible to the remote addresses that I used

$_SERVER['REMOTE_ADDRESS']

but I want to make it visible on my local network.

How can i do this?

+5
source share
4 answers

also in .htaccess, which you can allow from your ip / subnet, for example:

Order Deny,Allow
Deny from all
Allow from 192.168.1.1/24

of course it must match your local network

+12
source

You must do this in the .htaccess file.

First you specify Deny All, then specify a list of IP addresses that should be allowed.

order deny,allow
deny from all
allow from X.X.X.X
allow from X.X.X.X
allow from X.X.X.X

You can enable the following ranges:

allow from 10.0.0.0-10.255.255.255
allow from 10.0-255.0-255.0-255
allow from 10.*.*.*

1.2.3.254, 1.2.3.255, 1.2.4.1, 1.2.4.2, 1.2.4.3 1.2.4.4,
:

allow from 1.2.3.254-1.2.4.4
+5

The highest voted answer is correct for Apache 2.2. If you are using 2.4, you should use something like this:

<Limit GET POST>
 Require all denied
 Require ip 192.168.1.0/24
</Limit>
+1
source

I'm not quite sure, but maybe this is a pretty good solution:

if( substr($_SERVER['REMOTE_ADDRESS'], 0, 3) == '10.' ) {
   // welcome...
}
0
source

All Articles