PHP マニュアル
前のページ | 付録 G予約語の一覧 | 次のページ

# 定義済の変数

## サーバ変数: `$_SERVER`

> 注意 4.1.0で導入されました。これ以前のバージョンでは、 `$HTTP_SERVER_VARS`を使用して下さい。

`$_SERVER` は、ヘッダ、パス、スクリプトの位置の ような情報を有する配列です。この配列のエントリは、Webサーバにより 生成されます。全てのWebサーバがこれら全てを提供する保障はありませ ん。サーバは、これらのいくつかを省略したり、この一覧にない他のも のを定義する可能性があります。これらの変数の多くは、 CGI 1.1 specificationで定義さ れています。したがって、これらについては定義されていることを期待 することができます。

これは、'スーパーグローバル(superglobal)'、または自動グローバル (automatic global)、変数です。これは、スクリプトの全てのスコープ で利用可能であることを意味します。関数やメソッドの中からこの変数 にアクセスする際に `$HTTP_SERVER_VARS` のように global $_SERVER; とする必要はありません。

`$HTTP_SERVER_VARS` の最初の情報は同じですが、 autoglobalではありません。(`HTTP_SERVER_VARS` と `$_SERVER`は異なる変数であり、PHPは異なる変数と して処理を行うことに注意して下さい)

register_globals ディ レクティブを設定した場合、これらの変数は、スクリプトのグローバル スコープ、つまり、配列 `$_SERVER` 及び `$HTTP_SERVER_VARS` 以外のグローバル変数として 利用可能となります。関連情報については、 register_globalsの使用法 という名前のセキュリティに関する章を参照下さい。 これらの各グローバル変数は、autoglobalではありません。

以下の各要素のいくつかは $_SERVER に現れない可能性があります。PHP をコマンドラインで実行している場合には、使用できるものは僅かである ことに注意して下さい。

'`PHP_SELF`'

  The filename of the currently executing script, relative to the document root. For instance, `$_SERVER['PHP_SELF']` in a script at the address `http://example.com/test.php/foo.bar` would be `/test.php/foo.bar`.

  If PHP is running as a command-line processor, this variable is not available.

'`argv`'

  Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.

'`argc`'

  Contains the number of command line parameters passed to the script (if run on the command line).

'`GATEWAY_INTERFACE`'

  What revision of the CGI specification the server is using; i.e. '`CGI/1.1`'.

'`SERVER_NAME`'

  The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

'`SERVER_SOFTWARE`'

  Server identification string, given in the headers when responding to requests.

'`SERVER_PROTOCOL`'

  Name and revision of the information protocol via which the page was requested; i.e. '`HTTP/1.0`';

'`REQUEST_METHOD`'

  Which request method was used to access the page; i.e. '`GET`', '`HEAD`', '`POST`', '`PUT`'.

'`QUERY_STRING`'

  The query string, if any, via which the page was accessed.

'`DOCUMENT_ROOT`'

  The document root directory under which the current script is executing, as defined in the server's configuration file.

'`HTTP_ACCEPT`'

  Contents of the `Accept:` header from the current request, if there is one.

'`HTTP_ACCEPT_CHARSET`'

  Contents of the `Accept-Charset:` header from the current request, if there is one. Example: '`iso-8859-1,*,utf-8`'.

'`HTTP_ACCEPT_ENCODING`'

  Contents of the `Accept-Encoding:` header from the current request, if there is one. Example: '`gzip`'.

'`HTTP_ACCEPT_LANGUAGE`'

  Contents of the `Accept-Language:` header from the current request, if there is one. Example: '`en`'.

'`HTTP_CONNECTION`'

  Contents of the `Connection:` header from the current request, if there is one. Example: '`Keep-Alive`'.

'`HTTP_HOST`'

  Contents of the `Host:` header from the current request, if there is one.

'`HTTP_REFERER`'

  The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify `HTTP_REFERER` as a feature. In short, it cannot really be trusted.

'`HTTP_USER_AGENT`'

  Contents of the `User_Agent:` header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: `Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)`. Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent.

'`REMOTE_ADDR`'

  The IP address from which the user is viewing the current page.

'`REMOTE_PORT`'

  The port being used on the user's machine to communicate with the web server.

'`SCRIPT_FILENAME`'

  The absolute pathname of the currently executing script.

'`SERVER_ADMIN`'

  The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host.

'`SERVER_PORT`'

  The port on the server machine being used by the web server for communication. For default setups, this will be '`80`'; using SSL, for instance, will change this to whatever your defined secure HTTP port is.

'`SERVER_SIGNATURE`'

  String containing the server version and virtual host name which are added to server-generated pages, if enabled.

'`PATH_TRANSLATED`'

  Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.

'`SCRIPT_NAME`'

  Contains the current script's path. This is useful for pages which need to point to themselves.

'`REQUEST_URI`'

  The URI which was given in order to access this page; for instance, '`/index.html`'.

## 環境変数: `$_ENV`

> 注意 4.1.0で導入されました。これ以前のバージョンの場合は、 `$HTTP_ENV_VARS`を使用して下さい。

These variables are imported into PHP's global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. Please see your shell's documentation for a list of defined environment variables.

Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_ENV; to access it within functions or methods, as you do with `$HTTP_ENV_VARS`.

`$HTTP_ENV_VARS` contains the same initial information, but is not an autoglobal. (Note that `HTTP_ENV_VARS` and `$_ENV` are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the `$_ENV` and `$HTTP_ENV_VARS` arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

## HTTPクッキー: `$_COOKIE`

> 注意 4.1.0で導入されました。これ以前のバージョンの場合は、 `$HTTP_COOKIE_VARS`を使用して下さい。

An associative array of variables passed to the current script via HTTP cookies. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_COOKIE; to access it within functions or methods, as you do with `$HTTP_COOKIE_VARS`.

`$HTTP_COOKIE_VARS` contains the same initial information, but is not an autoglobal. (Note that `HTTP_COOKIE_VARS` and `$_COOKIE` are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the `$_COOKIE` and `$HTTP_COOKIE_VARS` arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

## HTTP GET 変数: `$_GET`

> 注意 4.1.0で導入されました。これ以前のバージョンの場合は、 `$HTTP_GET_VARS`を使用して下さい。

An associative array of variables passed to the current script via the HTTP GET method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_GET; to access it within functions or methods, as you do with `$HTTP_GET_VARS`.

`$HTTP_GET_VARS` contains the same initial information, but is not an autoglobal. (Note that `HTTP_GET_VARS` and `$_GET` are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the `$_GET` and `$HTTP_GET_VARS` arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

## HTTP POST 変数: `$_POST`

> 注意 4.1.0で導入されました。これ以前のバージョンの場合は、 `$HTTP_POST_VARS`を使用して下さい。

An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with `$HTTP_POST_VARS`.

`$HTTP_POST_VARS` contains the same initial information, but is not an autoglobal. (Note that `HTTP_POST_VARS` and `$_POST` are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the `$_POST` and `$HTTP_POST_VARS` arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

## HTTPファイルアップロード変数: `$_FILES`

> 注意 4.1.0で導入されました。これ以前のバージョンの場合は、 `$HTTP_POST_FILES`を使用して下さい。

An associative array of items uploaded to the current script via the HTTP POST method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_FILES; to access it within functions or methods, as you do with `$HTTP_POST_FILES`.

`$HTTP_POST_FILES` contains the same information, but is not an autoglobal.

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the `$_FILES` and `$HTTP_POST_FILES` arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

## リクエスト変数: `$_REQUEST`

> 注意 4.1.0で導入されました。以前のバージョンには、同等な配列はありませ ん。

An associative array consisting of the contents of `$_GET`, `$_POST`, `$_COOKIE`, and `$_FILES`.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_REQUEST; to access it within functions or methods.

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the `$_REQUEST` array. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

## セッション変数: `$_SESSION`

> 注意 4.1.0で導入されました。これ以前のバージョンでは、 `$HTTP_SESSION_VARS`を使用して下さい。

An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with `$HTTP_SESSION_VARS`.

`$HTTP_SESSION_VARS` contains the same information, but is not an autoglobal.

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the `$_SESSION` and `$HTTP_SESSION_VARS` arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

## グローバル変数: `$GLOBALS`

> 注意 `$GLOBALS`は、PHP 3.0.0以降で利用可能です。

An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $GLOBALS; to access it within functions or methods.

## The previous error message: `$php_errormsg`

`$php_errormsg` is a variable containing the text of the last error message generated by PHP. This variable will only be available within the scope in which the error occurred, and only if the track_errors configuration option is turned on (it defaults to off).

前のページ | ホーム | 次のページ
予約語の一覧 | 上に戻る | 定義済のクラス