I am trying to set a variable that should be accessible from outside of PHP. Ideally, this should be a local variable, but environment variables are also welcome.
Firstly, I tried putenv() , but this does not work:
$ php -r "putenv ('PHP_TEST = string');"; echo $ PHP_TEST
$
When I call getenv() from the same script, this results in the correct string value. Safe mode is disabled, but the manual says that the prefix "PHP_" is vital with security =, so I use it just in case :)
Then I will try system() or shell_exec() :
$ php -r "shell_exec ('PHP_TEST = string');"; echo $ PHP_TEST
$ php -r "shell_exec ('export PHP_TEST = string');"; echo $ PHP_TEST
$
Is there a workaround? what could be the reason? I am using Ubuntu Linux 9.10 "Karmic", but the FreeBSD server gives the same result.
source share