PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

getenv - 環境変数の値を取得する | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

getenv

(PHP 4, PHP 5, PHP 7)

getenv環境変数の値を取得する

説明

string getenv ( string $varname [, bool $local_only = false ] )

環境変数の値を取得します。

phpinfo() を使えば、すべての環境変数の一覧を見ることができます。 これらの変数の多くは、 » RFC 3875 の section 4.1, "Request Meta-Variables" に挙げられているものです。

パラメータ

varname

変数の名前。

local_only

Set to true to only return local environment variables (set by the operating system or putenv).

返り値

varname が示す環境変数の値を返し、 環境変数 varname が存在しない場合はFALSEを返します。

変更履歴

バージョン 説明
5.5.38, 5.6.24, 7.0.9 local_only パラメーターが追加されました。

注意

警告

If PHP is running in a SAPI such as Fast CGI, this function will always return the value of an environment variable set by the SAPI, even if putenv() has been used to set a local environment variable of the same name. Use the local_only parameter to return the value of locally-set environment variables.

例1 getenv() の例

<?php
// getenv() の使用例
$ip getenv('REMOTE_ADDR');

// または単純にスーパーグローバル($_SERVER または $_ENV)を使用します
$ip $_SERVER['REMOTE_ADDR'];

// Safely get the value of an environment variable, ignoring whether 
// or not it was set by a SAPI or has been changed with putenv
$ip getenv('REMOTE_ADDR'true) ?: getenv('REMOTE_ADDR')
?>

参考


忘却曲線を使ってこの関数を確実に記憶に残す

フォーラムで「getenv - 環境変数の値を取得する」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | getenv - 環境変数の値を取得する」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: