自动检测内部/外部开发环境 [英] Auto detect internal/external development environment

查看:115
本文介绍了自动检测内部/外部开发环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用以下功能自动检测我们是在内部机器上还是在实时服务器上,然后为各种组件选择适当的配置:

We use the following function to auto detect if we are on a machine internally or on a live server and then choose the appropriate configs for various components:

function devIsLocal(){

    $res=false;

    $http_host=$_SERVER['HTTP_HOST'];

    if($http_host=='localhost')$res=true;
    if($http_host=='127.0.0.1')$res=true;
    if(substr($http_host,-4)=='.lan')$res=true;
    if(strpos($http_host, '.')===false)$res=true;

    return($res);

}

如您所见,它仅依赖于HTTP_HOST值.

As you can see it only relies on the HTTP_HOST value.

当然,如果您在本地使用某些虚拟主机(例如example.com),则该功能将受到欺骗.

Of course, if you use some sort of virtual host locally like example.com then the function will be tricked.

还有其他方法可以欺骗该功能吗?以及我们还可以窥视其他哪些变量/位置来确定我们的位置?

Are there any other ways to fool the function? and what other variables/places could we peek at to determine where we are?

推荐答案

'127.0.0.1' == $_SERVER["REMOTE_ADDR"]

这在您的实时系统上永远不会评估为TRUE. :)

This will never evaluate as TRUE on your live system. :)

这篇关于自动检测内部/外部开发环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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