getenv()


Overview

getenv() is a PHP function used to fetch environment variables.
Versions: PHP 4, PHP 5, PHP 7, PHP 8.

Note:
If PHP is running in a SAPI, only environment variables set by the SAPI are returned.

Parameters

getenv() can have two parameters:

name (main parameter): the name of the environment variable, either a string or null.
local_only: if set to true, only local environment variables are fetched, set by the OS or putenv().

Return possibilities

Returns the value of the environment variable. Returns false if the environment variable does not exist. If the name is null, all environment variables are returned in the format of an associative array.

Example

php
getenv('VARIABLE_NAME', true);

See also

putenv()
Apache logo. Copyright may apply. How to set an environment variable on Apache using .htaccess
Get an environment variable | PHP Snippets