Substitute for deprecated register_globals in php5 for updating path variables used by exec?
I am using php as a command line scripting language for executing various system commands.
The directive 'register_globals' is deprecated in PHP 5.3 and greater.
What is a clean way to update the PATH environment vari开发者_开发技巧able that is used by the exec command?
The following seems to throw away the value of PATH after the exec command finishes:
exec('PATH=$PATH:"' . $app_path .'"; export PATH' );
putenv() does this:
putenv('PATH=' . getenv('PATH') . ':' . $app_path);
You can get environment variables with getenv()
and set them with putenv()
.
Besides getenv(), you can access it from $_SERVER["PATH"]
.
The $_ENV
array is usually empty, due to the missing in E
in the variables_order=GPCS
configuration setting. (Has nothing to do with register_globals, but it's a related issue.)
精彩评论