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: Wed, 22 May 2013

view this page in

$_ENV

$HTTP_ENV_VARS [obsoleta]

(PHP 4 >= 4.1.0, PHP 5)

$_ENV -- $HTTP_ENV_VARS [obsoleta]Variables de entorno

Descripción

Una variable tipo array asociativo de variables pasadas al script actual a través del método del entorno.

Estas variables son importadas en el espacio de nombres global de PHP desde el entorno bajo el que está siendo ejecutado el intérprete PHP. Muchas son entregadas por el intérprete de comandos bajo el que PHP está corriendo y diferentes sistemas suelen tener diferentes tipos de intérpretes de comandos, una lista definitiva es imposible. Por favor consulte la documentación de su intérprete de comandos para una lista de las variables de entorno que se definen.

Otras variables de entorno incluyen las variables CGI, colocadas allí independientemente de que PHP esté siendo ejecutado como módulo del servidor o procesador CGI.

$HTTP_ENV_VARS contiene la misma información inicial, pero no es una superglobal. (Note que $HTTP_ENV_VARS y $_ENV son variables diferentes y que PHP las trata como tal)

Historial de cambios

Versión Descripción
4.1.0 Se introdujo $_ENV, haciendo $HTTP_ENV_VARS obsoleta.

Ejemplos

Ejemplo #1 Ejemplo de $_ENV

<?php
echo '¡Mi nombre de usuario es ' $_ENV["USER"] . '!';
?>

Asumiendo que "bjori" ejecuta este script

El resultado del ejemplo sería algo similar a:

¡Mi nombre de usuario es bjori!

Notas

Nota:

Esta es una 'superglobal' o una variable automatic global. Significa simplemente que es una variable que está disponible en cualquier parte del script. No hace falta hacer global $variable; para acceder a la misma desde funciones o métodos.

Ver también



$_COOKIE> <$_SESSION
[edit] Last updated: Wed, 22 May 2013
 
add a note add a note User Contributed Notes $_ENV - [5 notes]
up
3
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
2
gabe-php at mudbugmedia dot com
2 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
2
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
1
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
0
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 | sitemap | contact | advertising | mirror sites