downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

$_COOKIE> <$_SESSION
[edit] Last updated: Fri, 24 Feb 2012

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)

Histórico

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 a:

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, 24 Feb 2012
 
add a note add a note User Contributed Notes $_ENV
david at davidfavor dot com 07-Feb-2012 07:07
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'.
anonymous 09-Sep-2010 04:36
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).
gabe-php at mudbugmedia dot com 26-May-2010 03:11
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.
php at isnoop dot net 01-Apr-2010 03:33
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.
ewilde aht bsmdevelopment dawt com 19-Mar-2009 11:48
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 = "";
?>

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