Hi i've got another question, i'm writing a simple website in PHP and i have problem with visibility of my website in local network to make it visible to remote addresses i used
$_SERVER['REMOTE_ADDRESS']
, but i want to make it visible in my LAN.
How can i do this ??
also in .htaccess you can allow from your ip/subnet, like this:
Order Deny,Allow
Deny from all
Allow from 192.168.1.1/24
of course it should match your LAN
I'm not totally sure but maybe this is a good enough solution:
if( substr($_SERVER['REMOTE_ADDRESS'], 0, 3) == '10.' ) {
// welcome...
}
You should be doing this in your .htaccess file.
First you specify a 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 allow ranges like this:
allow from 10.0.0.0-10.255.255.255
allow from 10.0-255.0-255.0-255
allow from 10.*.*.*
If you want to allow 1.2.3.254
, 1.2.3.255
, 1.2.4.1
, 1.2.4.2
, 1.2.4.3
, and 1.2.4.4
,
you can do it like this:
allow from 1.2.3.254-1.2.4.4
The highest voted answer is true for Apache 2.2. If you use 2.4, you have to use something like this:
<Limit GET POST>
Require all denied
Require ip 192.168.1.0/24
</Limit>
order deny,allow
deny from all
allow from ::1
allow from 192.168.0.1 etc...
The ::1
works great (this is also specified in the windows host file).