PHP Tutorial PHP Advanced PHP References

PHP $_ENV Variable



The PHP $_ENV is a built-in super global variable which is always available in all scopes. The $_ENV is an associative array which contains the variables passed to the current script via the environment method.

These variables are imported into PHP's global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. See the shell's documentation for a list of defined environment variables.

Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor.

Example: $_ENV example

The example below demonstrates the usage of $_ENV variable.

<?php
echo 'Username: '.$_ENV["USER"].'!';
?>

Assuming "John" executes the above script.

The output of the above script will be similar to:

Username: John!

❮ PHP - Predefined Variables