SERVER_NAME is the name defined in the apache configuration.
HTTP_HOST is the host header sent by the client when using the more recent versions of the http protocol.
getenv
(PHP 4, PHP 5)
getenv — Retourne la valeur d'une variable d'environnement
Description
string getenv
( string $varname
)
Retourne la valeur d'une variable d'environnement.
Vous pouvez voir une liste complète des variables d'environnement en utilisant la fonction phpinfo(). Vous pouvez trouver la signification de chacune d'entre elles en consultant le site concernant » "CGI specification" (en anglais), et particulièrement la page concernant les » variables d'environnement.
Liste de paramètres
- varname
-
Le nom de la variable.
Valeurs de retour
Retourne la valeur de la variable d'environnement varname , ou FALSE en cas d'erreur.
Exemples
Exemple #1 Exemple avec getenv()
<?php
// Exemple d'utilisation de getenv()
$ip = getenv('REMOTE_ADDR');
// Ou utilisez simplement une Superglobale ($_SERVER ou $_ENV)
$ip = $_SERVER['REMOTE_ADDR'];
?>
getenv
sam at sambarrow dot com
13-Mar-2008 02:32
13-Mar-2008 02:32
renko at <remove>virtual-life dot net
08-Nov-2004 03:40
08-Nov-2004 03:40
The function 'getenv' does not work if your Server API is ASAPI (IIS).
So, try to don't use getenv('REMOTE_ADDR'), but $_SERVER["REMOTE_ADDR"].
kyong
04-Feb-2004 10:06
04-Feb-2004 10:06
As you know, getenv('DOCUMENT_ROOT') is useful.
However, under CLI environment(I tend to do quick check
if it works or not), it doesn't work without modified php.ini
file. So I add "export DOCUMENT_ROOT=~" in my .bash_profile.
daman at SPAM_BlockERmralaska dot com
08-Sep-2002 03:37
08-Sep-2002 03:37
Be careful using HTTP_X_FORWARDED_FOR in conditional statements collecting the IP address. Sometimes the user's LAN address will get forwarded, which of course is pretty worthless by itself.
alex at acid-edge dot net
23-Jul-2002 07:32
23-Jul-2002 07:32
Note that some caches seem to send the client-ip header *backwards*. be careful :)
john-php at pc dot xs4all dot nl
16-Aug-2000 03:56
16-Aug-2000 03:56
Note that the X-Forwarded for header might contain multiple addresses, comma separated, if the request was forwarded through multiple proxies.
Finally, note that any user can add an X-Forwarded-For header themselves. The header is only good for traceback information, never for authentication. If you use it for traceback, just log the entire X-Forwarded-For header, along with the REMOTE_ADDR.
