Home  >  Article  >  Backend Development  >  What are the predefined variables in php?

What are the predefined variables in php?

怪我咯
怪我咯Original
2017-06-19 14:32:142983browse

Superglobal variable

Superglobal variables are internal variables that can always be used in all scopes . There is also no need to execute global $variable; in a function or method to access them.

【$GLOBALS】

 References all variables available in the global scope. Is a global combined array containing global variables, the name of the variable is the key of the array.

【$_SERVER】

An array containing header information, path, script location and other information. The elements of this array are created by the web server.

PHP_SELF: The file name of the currently executing script, related to document root. For example: a script with the address http://example.com/test/php/foo.bar, $_SERVER['PHP_SELF']='/test.php/foo.bar'. (The FILE constant contains the full path and file name of the current file)

argv: Array of parameters passed to the script. When the script is run in CLI mode, argv is passed to the program as C-style command line arguments. When called through GET, the change contains Query String.

argc: The number of arguments passed to the script in CLI run mode.

GATEWAY_INTERFACE: The version of the CGI specification used by the server. For example: "CGI/1.1".

SERVER_ADDR: The IP address of the server where the script is currently running.

SERVER_NAME: The host name of the server where the script is currently running. If the script is running in a virtual host, this variable is determined by the value set by the virtual host.

SERVER_SOFTWARE: Server identification string, given in the header information of the response request.

SERVER_PROTOCOL: The name and version of the communication protocol when requesting the page. For example: "HTTP/1.0".

REQUEST_METHOD: The method used to access the page. Such as: GET, HEAD, POST, PUT. (If the request method is HEAD, the PHP script will terminate after the Header header information, no output will be produced, and there will be no output buffering)

REQUEST_TIME: The timestamp when the request started.

QUERY_STRING: Query string. If available, page access is made through it.

DOCUMENT_ROOT: The document root directory where the currently running script is located. Defined in the server configuration file.

HTTP_ACCEPT: The content of the Accept item in the current request header (if it exists).​

HTTP_ACCEPT_CHARSET: The content of the Accept-Charset item in the current request header (if it exists).

HTTP_ACCEPT_ENCODING: The content of the Accept-Encoding item in the current request (if it exists).

HTTP_ACCEPT_LANGUAGE: The content of the Accept-Language item in the current request (if it exists).

HTTP_CONNECTION: The content of the Connection item in the current request header (if it exists).

HTTP_HOST: The content of the Host item in the current request header (if it exists).

HTTP_REFERER: Directs the user agent to the address of the previous page of the current page (if it exists). Determined by user agent settings. Not all users will set this item, and some also provide the function of modifying HTTP_REFERER. So the value is not trustworthy.

HTTP_USER_AGENT: The content of the User-Agent item in the current request header (if it exists). This string indicates the user agent information for accessing this page, such as: Mozilla/4.5[en] (X11;U;Linux 2.2.9 i586). In addition, the value can be obtained using get_browser().

HTTPS: If the script is accessed via the HTTPS protocol, this value is set to a non-empty value. When using the ISAPI method on IIS, if it is not accessed through the HTTPS protocol, the value will be off.

REMOTE_ADDR: The IP address of the user browsing the current page.

REMOTE_HOST: The host name of the user browsing the current page. DNS reverse resolution does not depend on the user's REMOTE_ADDR. The server must be configured in order to generate this variable, such as setting HostnameLookups On in Apache.

REMOTE_PORT: The port number used by the user machine to connect to the Web server.

SCRIPT_FILENAME: The absolute path of the currently executing script.

SERVER_ADMIN: This value specifies the SERVER_ADMIN parameter in the Apache server configuration file. If the script is running on a virtual host, this value is that of that virtual host.

SERVER_PORT: The port used by the web server. The default is 80. If using SSL secure connection, this value is the HTTP port set by the user.

SERVER_SIGNATURE: A string containing the server version and virtual machine host name.

PATH_TRANSLATED: The base path of the file system (not the document root directory) where the current script is located. This is the result of a virtual to real path image of the server.

SCRIPT_NAME: Contains the path of the current script.

REQUEST_URI: URI is used to specify the page to be accessed.

PHP_AUTH_DIGEST: When running as an Apache module, during the HTTP Digest authentication process, the change amount is set to the "Authorization" HTTP header content sent by the client.

## PHP_AUTH_USER: When PHP is running under the Apache or IIS module and is using the HTTP authentication function, the change amount is the user name entered by the user.

PHP_AUTH_PW: When PHP is running under the Apache or IIS module and is using the HTTP authentication function, the change amount is the password entered by the user.

AUTH_TYPE: When PHP is running in Apache module mode and is using the HTTP authentication function, the variable is the type of authentication.

PATH_INFO: Contains the path information provided by the client, following the real script name and before the query statement (if it exists).

ORIG_PATH_INFO: The original version of "PATH_INFO" before being processed by PHP.

【$_GET】

## HTTP GET variable.

# Array containing variables passed to the current script via URL parameters.

Passed through urldecode().

echo htmlspecialchars($_GET['name']);

【$_POST】

HTTP POST variable.

Array of variables passed to the current script via the HTTP POST method.

echo htmlspecialchars($_POST['name']);

【$_FILES】 HTTP file upload variable.

An array of files uploaded to the current script via HTTP POST.

【$_REQUEST】 HTTP

REQUEST variable

. By default, it contains an array of $_GET, $_POST, and $_COOKIE.

Set the order of GPC through PHP's variables_order directive or import_request_variables().

【$_SESSION】 Session variable.

【$_ENV】 Environment variables.

An array of variables passed to the current script through the environment. These variables are imported into PHP's global namespace by the PHP parser runtime environment. Many are provided by shells that support PHP running.

【$_COOKIE】 HTTP Cookies.

An array of variables passed to the current script through HTTP Cookies.

【$php_errormsg】 Previous error message.

 $php_errormsg contains the latest error messages generated by PHP. Changes are only available in the scope where the error occurred, and require the track_errors configuration item to be turned on (the default is off).

If the user defines an error handling handler (

set_error_handler

()) and returns FALSE, $php_errormsg will be set.

【$HTTP_RAW_POST_DATA】 Native POST data. Contains the raw data submitted by POST.

【$http_response_header】

HTTP response header.

Similar to get_header(). When using HTTP wrappers, the mutator will be populated with HTTP response headers. The variable will be created in the local scope.

[$argc]

The number of parameters passed to the script in CLI mode. Only available when register_argc_argv is on.

The script file name is always passed as a parameter to the current script.

[$argv]

Array of parameters passed to the script. Only available when register_argc_argv is on.

The first parameter is always the file name of the current script.

The above is the detailed content of What are the predefined variables in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn