原来这里有两个问题:
1.$_ENV
仅在php.ini允许的情况下进行填充,默认情况下似乎没有这样做,至少在默认的WAMP服务器安装中没有。
; This directive determines which super global arrays are registered when PHP
; starts up. If the register_globals directive is enabled, it also determines
; what order variables are populated into the global space. G,P,C,E & S are
; abbreviations for the following respective super globals: GET, POST, COOKIE,
; ENV and SERVER. There is a performance penalty paid for the registration of
; these arrays and because ENV is not as commonly used as the others, ENV is
; is not recommended on productions servers. You can still get access to
; the environment variables through getenv() should you need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http:
variables_order = "GPCS"
当我将variables_order
back设置为时EGPCS
,$_ENV
不再为空。
2.当您SetEnv
在中使用时.htaccess
,它以而$_SERVER
不是中结束$_ENV
,我得说它的名字有点令人困惑SetEnv
。
SetEnv ENV dev
SetEnv BASE /ssl/
var_dump($_SERVER['ENV'], $_SERVER['BASE']);
3.该getenv
函数将始终运行,并且不受$ _ENV的PHP设置的影响。此外,它似乎对大小写不敏感,这可能很有用。
var_dump(getenv('os'), getenv('env'));
$_SERVER
var发送的原因。我会投票支持使用getenv()
它,就我所收集的而言,它们仅搜索不区分大小写的内容。