PHP - 如何使页面仅在本地网络中可见

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10455996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:11:58  来源:igfitidea点击:

PHP - how to make page visible only in local network

php.htaccesslan

提问by arclite

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

嗨,我还有另一个问题,我正在用 PHP 编写一个简单的网站,但我的网站在本地网络中的可见性存在问题,无法使其对我使用的远程地址可见

$_SERVER['REMOTE_ADDRESS']

, but i want to make it visible in my LAN.

,但我想让它在我的局域网中可见。

How can i do this ??

我怎样才能做到这一点 ??

回答by evaldasc

also in .htaccess you can allow from your ip/subnet, like this:

同样在 .htaccess 中,您可以从您的 ip/子网中允许,如下所示:

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

of course it should match your LAN

当然它应该匹配你的局域网

回答by Ozzy

You should be doing this in your .htaccess file.

您应该在 .htaccess 文件中执行此操作。

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

首先指定拒绝全部,然后指定应该允许的 IP 地址列表。

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:

如果你想允许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
你可以这样做:

allow from 1.2.3.254-1.2.4.4

回答by Nikolaos Christos Nikolaidis

The highest voted answer is true for Apache 2.2. If you use 2.4, you have to use something like this:

对于 Apache 2.2,得票最高的答案是正确的。如果你使用 2.4,你必须使用这样的东西:

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

回答by Regardt

order deny,allow
deny from all
allow from ::1
allow from 192.168.0.1 etc...

The ::1works great (this is also specified in the windows host file).

::1工程巨大(这也是在Windows主机文件中指定)。

回答by xCander

I'm not totally sure but maybe this is a good enough solution:

我不完全确定,但也许这是一个足够好的解决方案:

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