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

search for in the

getlastmod> <get_required_files
Last updated: Fri, 22 Aug 2008

view this page in

getenv

(PHP 4, PHP 5)

getenvLiefert den Wert einer Umgebungsvariable

Beschreibung

string getenv ( string $varname )

Liefert den Wert einer Umgebungsvariable.

Eine Liste aller Umgebungsvariablen können Sie über die Funktion phpinfo() anzeigen lassen. Die Bedeutung vieler dieser Variablen können Sie in der » CGI Spezifikation im Abschnitt über » Umgebungsvariablen.

Parameter-Liste

varname

Der Variablenname

Rückgabewerte

Gibt den Wert der Umgebungsvariable varname zurück oder FALSE bei Fehlern

Beispiele

Beispiel #1 getenv() Beispiel

<?php
// nutzen Sie getenv() ...
$ip getenv('REMOTE_ADDR');

// ... oder einfache die superglobalen Arrays ($_SERVER oder $_ENV)
$ip $_SERVER['REMOTE_ADDR'];
?>



getlastmod> <get_required_files
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
getenv
sam at sambarrow dot com
13-Mar-2008 02:32
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.
renko at <remove>virtual-life dot net
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
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
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
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
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.
sorry at spammed dot nut
12-Jul-1999 04:43
To show a use of getenv("QUERY_STRING")....

suppose you have a site with frames...  the frames create the "interface", and one frame called "main" has an active document...  now, suppose you made a page.php3 which took an argument "pg" and spit out the framesets necessary, with "main" frame containing whatever "pg" is...  so now you can bring up any page in your site with page.php3?pg=test.html
now, take this one step further, and suppose you want outside links to point to php3 pages which takes parameters, ON your site...  but you still want them to appear in frames, so what do you do?  well, if "ok.php3" was the page you wanted to show, and it was requested as "ok.php3?some=params&go=here", then the very thing in the beginning of ok.php3 could be  :
<?php
if (!isset($inframe)) {
header("Location: http://yoursite/page.php3?pg=".urlencode("inframes=1&").getenv("QUERY_STRING"));
exit;
}
?>
Now... you might ask, how in the world did I come up with THAT?  Well, perhaps it was because I came here not able to remember which environment variable held the query string...

getlastmod> <get_required_files
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites