dismiss Step into the future! Click here to switch to the beta php.net site
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

$_COOKIE> <$_SESSION
[edit] Last updated: Fri, 28 Jun 2013

view this page in

$_ENV

$HTTP_ENV_VARS [obsoleta]

$_ENV -- $HTTP_ENV_VARS [obsoleta]Environment variables

Descrição

Um array associativo de variáveis passadas para o script atual via o método do ambiente.

Estas variáveis são importadas para o PHP do ambiente sob o qual o parser do PHP é executado. Muitas são providas pelo shell sob o qual o PHP é executado e diferentes sistemas são prováveis executar diferentes tipos de shells, uma lista definitiva é impossível. Veja a documentação de shellp para saber a lista de variáveis de ambiente definidas.

Outras variáveis de ambiente incluem variáveis CGI, elas aparecem desconsiderando se o PHP é executado como um módulo do servidor ou processador CGI.

$HTTP_ENV_VARS contém a mesma informação inicial, mas não é uma superglobal. (Note que $HTTP_ENV_VARS e $_ENV são variáveis diferentes e que o PHP manuseia-as diferentemente)

Changelog

Versão Descrição
4.1.0 Introduzida a $_ENV que torna obsoleta a $HTTP_ENV_VARS.

Exemplos

Exemplo #1 Exemplo da $_ENV

<?php
echo 'My username is ' .$_ENV["USER"] . '!';
?>

Assumindo que "bjori" executou este script

O exemplo acima irá imprimir algo similar à:

My username is bjori!

Notas

Nota:

Esta é uma 'superglobal', ou global automática, variável. Isto simplismente significa que ela está disponível em todos escopos pelo script. Não há necessidade de fazer global $variable; para acessá-la dentro de uma função ou método.

Veja Também



$_COOKIE> <$_SESSION
[edit] Last updated: Fri, 28 Jun 2013
 
add a note add a note User Contributed Notes $_ENV - [5 notes]
up
3
gabe-php at mudbugmedia dot com
3 years ago
If your $_ENV array is mysteriously empty, but you still see the variables when calling getenv() or in your phpinfo(), check your http://us.php.net/manual/en/ini.core.php#ini.variables-order ini setting to ensure it includes "E" in the string.
up
3
php at isnoop dot net
3 years ago
If you wish to define an environment variable in your Apache vhost file, use the directive SetEnv.

SetEnv varname "variable value"

It is important to note that this new variable will appear in $_SERVER, not $_ENV.
up
2
david at davidfavor dot com
1 year ago
Comments for this page seem to indicate getenv() returns environment variables in all cases.

For getenv() to work, php.ini variables_order must contain 'E'.
up
2
ewilde aht bsmdevelopment dawt com
4 years ago
When running a PHP program under the command line, the $_SERVER["SERVER_NAME"] variable does not contain the hostname. However, the following works for me under Unix/Linux and Windows:

<?php
if (isset($_ENV["HOSTNAME"]))
   
$MachineName = $_ENV["HOSTNAME"];
else if  (isset(
$_ENV["COMPUTERNAME"]))
   
$MachineName = $_ENV["COMPUTERNAME"];
else
$MachineName = "";
?>
up
1
anonymous
2 years ago
If $_ENV is empty because variables_order does not include it, it will be filled with values fetched by getenv().

For example, when calling getenv("REMOTE_ADDR"), $_ENV['REMOTE_ADDR'] will be defined as well (if such an environment variable exists).

 
show source | credits | stats | sitemap | contact | advertising | mirror sites