phpday 2027 - Call for Papers

apache_getenv

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

apache_getenv — Apache の subprocess_env 変数を取得する

説明

function apache_getenv(string $variable, bool $walk_to_top = false): string|false

variable で指定された Apache 環境変数を取得します。

パラメータ

variable

Apache の環境変数を指定します。

walk_to_top

全ての Apache レイヤについてのトップレベル変数を取得するかどうか を指定します。

戻り値

成功時は Apache 環境変数の値、失敗時は false を返します。

例

例1 apache_getenv() の例

この例は、Apache の環境変数 SERVER_ADDR をどの様に取得するかを示しています。

<?php
$ret = apache_getenv("SERVER_ADDR");
echo $ret;
?>

上の例の出力は、 たとえば以下のようになります。

42.24.42.240

参考

User Contributed Notes 2 notes

up
6
elhachmi at gmail dot com
13 years ago
apache_getenv(key) does not work on an php cgi installation, in this case rather use $_SERVER["REDIRECT_key"]
up
1
Anonymous
8 years ago
This manual page is unclear as to whether it will fetch Apache configuration environment variables set by "SetEnv" (including "SetEnvIf[NoCase]" or "BrowserMatch" e.g.) as the only example given is with a pre-defined CGI interface variable (which is also available via the $_SERVER[] array).  If custom Apache runtime configuration variables are indeed fetchable via this interface, let's say so or give an example of such.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top