8.21. Reading Environment Variables
Read the value from the $_ENV superglobal array:
$name = $_ENV['USER'];
print $_ENV['HOME']; // user's home directory /home/adam
Early versions of PHP automatically created PHP variables for all environment variables by default. As of 4.1.0, php.ini-recommended disables this because of speed considerations; however php.ini-dist continues to enable environment variable loading for backward compatibility.
$path = getenv('PATH');
The getenv( ) function isn't available if you're running PHP as an ISAPI module.
8.21.4. See Also
Recipe 8.22 on setting environment variables; documentation on getenv( ) at http://www.php.net/getenv; information on environment variables in PHP at http://www.php.net/reserved.variables.php#reserved.variables.environment.
Copyright © 2003 O'Reilly & Associates. All rights reserved.