Auto detect internal/external development environment
Posted
by zaf
on Stack Overflow
See other posts from Stack Overflow
or by zaf
Published on 2010-04-09T11:50:56Z
Indexed on
2010/04/09
11:53 UTC
Read the original article
Hit count: 381
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);
}
As you can see it only relies on the HTTP_HOST value.
Of course, if you have use 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?
© Stack Overflow or respective owner