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, 25 May 2012

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: Fri, 25 May 2012
 
add a note add a note User Contributed Notes $_ENV
david at davidfavor dot com 07-Feb-2012 02: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 10: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 09: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 09: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 20-Mar-2009 05: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