home

Php Env Tutorial


$_ENV is a superglobal that contains environment variables. Environment variables are provided by the shell under which PHP is running, so they may vary according to different shells.

You can display all your environment variables pronting out $_ENV:

<?php 
echo "<pre>";
print_r($_ENV);
echo "</pre>";

/* ****environment variables on a mac machine****
Array
(
[SHELL] => ***
[TMPDIR] => ***
[Apple_PubSub_Socket_Render] => ***
[USER] => ***
[SSH_AUTH_SOCK] => ***
[__CF_USER_TEXT_ENCODING] => ***
[PATH] => ***
[PWD] => ***
[HOME] => ***
[SHLVL] => ***
[DYLD_LIBRARY_PATH] => ***
[LOGNAME] => ***
[__LAUNCHD_FD] => ***
[DISPLAY] => ***
[_] => ***
[COMMAND_MODE] => ***
)
*/

?>

To display an environment variable you can also use getenv()

<?php 
echo getenv('USER');
?>

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

Copyright © 2014 by Cramerz.com.