It turns out there were two problems:
1. $_ENV populated only if php.ini allows it , which apparently does not run by default, at least when installing the default WAMP server .
; 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://php.net/variables-order variables_order = "GPCS"
When I returned variables_order back to EGPCS , $_ENV will no longer be empty.
2. When you use SetEnv in your .htaccess , it ends in $_SERVER , not $_ENV , which, as I have to say, is a little confusing when it is called SetEnv ...
# .htaccess SetEnv ENV dev SetEnv BASE /ssl/
3. The getenv function will always work and will not depend on the PHP settings for $ _ENV . In addition, it does not seem to be case sensitive, which may be useful.
var_dump(getenv('os'), getenv('env')); // string 'Windows_NT' (length=10) // string 'dev' (length=3)
Svish Nov 22 '14 at 12:36 2014-11-22 12:36
source share