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
Last updated: Fri, 20 May 2011

view this page in

$_ENV

$HTTP_ENV_VARS [obsoleta]

$_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

Example #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

Note:

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
Last updated: Fri, 20 May 2011
 
add a note add a note User Contributed Notes $_ENV
anonymous 09-Sep-2010 05: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 04: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 05: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 01: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