如何检测,如果本地主机上运行 [英] How to detect if running on localhost

查看:113
本文介绍了如何检测,如果本地主机上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,我想检测用户是否在本地机器上运行,而不是在互联网上访问。目前我检查服务器地址127.0.0.1他。这是最好的做法还是有更好的办法?

I have a PHP script where I'd like to detect if the user is running on a local machine, not accessible over the Internet. Currently I check for the server address to he 127.0.0.1. Is this the best practice or is there a better way?

推荐答案

本地主机始终将转换为回送IP地址 127.0.0.1 在IPv4中,或 :: 1 在IPv6中,所以验证IP在你的应用是安全的,如果你的意思是

Localhost always translates to the loopback IP address 127.0.0.1 in IPv4, or ::1 in IPv6, So validating the IP Within your application would be secure, if you mean

if(IPAddress::In(array("127.0.0.1","::1")))
{
     //Show Application
}

我很怀疑,你将有一个团队的精英黑客你的端口80后,但作为一个侧面说明已有一些谈瑕疵依靠如TCP数据包可以修改IP地址。

I Very much doubt that you will have a team of elite hackers after your port 80 but as a side note there has been some talk about flaws in relying on an IP address as TCP Packets can be modified.

但是这不应该成为你的烦恼。

But that should not be a worry for you.

这篇关于如何检测,如果本地主机上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆