Home  >  Article  >  Backend Development  >  Predefined variables_PHP tutorial

Predefined variables_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:58:36828browse

Server variable: $_SERVER
Note: Used in PHP 4.1.0 and later versions. Previous versions, used $HTTP_SERVER_VARS.

$_SERVER is an array containing things like headers, paths, and script locations. The entities of the array are created by the web server. There is no guarantee that all servers will produce all messages; servers may ignore some messages or generate new messages not listed below. This means that a large number of these variables are specified in the CGI 1.1 specification, so you should study it carefully.

This is a "superglobal", or can be described as an automatic global variable. This just means that it works in all scripts. You do not need to use global $_SERVER; to access it within a function or method, as you would with $HTTP_SERVER_VARS.

$HTTP_SERVER_VARS contains the same information, but is not an automatic global variable. (Note: $HTTP_SERVER_VARS and $_SERVER are different variables, and PHP handles them differently.)

These variables are also available in all scripts if the register_globals directive is set; that is, the $_SERVER and $HTTP_SERVER_VARS arrays are separated. For related information, see the security-related chapter Using Register Globals. These individual global variables are not automatic global variables.

You may find that some of the $_SERVER elements listed below are not available. Note that if you run PHP from the command line, almost none of the elements listed below are valid (or have no practical meaning).



"PHP_SELF"
The file name of the currently executing script, related to the document root. For example, using $_SERVER['PHP_SELF'] in a script with the URL address http://example.com/test.php/foo.bar will result in /test.php/foo.bar.

If PHP is run from the command line, this variable has no effect.

"argv"
Parameters passed to this script. When the script is run in command-line mode, the argv variable is passed to the program as C-style command-line arguments. When the GET method is called, this variable contains the requested data.

"argc"
Contains the number of command line arguments passed to the program (if running in command line mode).

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

'SERVER_NAME'
The name of the server host where the script is currently running. If the script is running on a virtual host, the name is determined by the value set for that virtual host.

'SERVER_SOFTWARE'
A string identifying the server as given in the header of the response to the request.

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

"REQUEST_METHOD"
The request method when accessing the page. For example: "GET", "HEAD", "POST", "PUT".

"QUERY_STRING"
The string of query.

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

"HTTP_ACCEPT"
The contents of the Accept: header of the current request.

"HTTP_ACCEPT_CHARSET"
The contents of the Accept-Charset: header of the current request. For example: "iso-8859-1,*,utf-8".

"HTTP_ACCEPT_ENCODING"
The contents of the Accept-Encoding: header of the current request. For example: "gzip".

"HTTP_ACCEPT_LANGUAGE"
The contents of the Accept-Language: header of the current request. For example: "en".

"HTTP_CONNECTION"
The contents of the Connection: header of the current request. For example: "Keep-Alive".

"HTTP_HOST"
The contents of the Host: header of the current request.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631391.htmlTechArticleServer variable: $_SERVER Note: Used in PHP 4.1.0 and later versions. Previous versions, used $HTTP_SERVER_VARS. $_SERVER is a file containing headers, paths and scripts...
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