PHP predefined variables using Help (with instance) _php instance

Source: Internet
Author: User
Tags documentation http authentication http cookie http digest authentication http file upload http post php script versions

The preferred method for obtaining external variables from PHP 4.1.0 is to use the Super global variables mentioned below. Before that, people either relied on register_globals, or long predefined PHP arrays ($HTTP _*_vars). Long-form PHP predefined variables can be masked by setting register_long_arrays from PHP 5.0.0.


Server variables: $_server


Note: Used in PHP 4.1.0 and later versions. Previous versions, using the $HTTP _server_vars.


A $_server is an array that contains such things as header information (header), path (path), and script location (scripts locations). The entities of the array are created by the Web server. There is no guarantee that all servers will generate all the information, the server may have overlooked some information, or some new information that has not been listed below. This means that a large number of these variables are described in the CGI 1.1 specification, so it should be studied carefully.


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


$HTTP _server_vars contains the same information, but not an automatic global variable (note: $HTTP _server_vars and $_server are different variables that PHP handles differently).


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_server and $HTTP _server_vars arrays are separated. For information, please refer to the Security section for the use of the 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 on a command-line basis, the elements listed below are almost not valid (or meaningless).


"Php_self"


The name of the file that is currently executing the script, related to document root. For example, using $_server[' php_self ' in a script with a URL address of Http://example.com/test.php/foo.bar will get/test.php/foo.bar this result. The __FILE__ constant contains the absolute path and file name of the current (for example, included) file.


If PHP runs on a command-line basis, the variable is not valid until PHP 4.3.0.


"ARGV"


The arguments passed to the script. When the script runs on the command-line, the ARGV variable is passed to the program C language-style command-line argument. When you call the Get method, the variable contains the requested data.


"ARGC"


Contains the number of command-line arguments that are 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 on which the script is currently running. If the script is running on a virtual host, the name is determined by the value set by that virtual host.


"Server_software"


A string of server identities, given in the header information in response to the request.


"Server_protocol"


The name and version of the communication protocol when the page is requested. For example, "http/1.0".


"Request_method"


The request method when accessing the page. For example:, POST and put.


Note: If the request is in the way that the head,php script will abort after the message is sent (this means that there is no output buffer after any output is generated).


"Request_time"


Time stamp at the start of the request. Valid from PHP 5.1.0.


"Query_string"


string of Queries (query) (the first question mark in the URL?) After the content).


"Document_root"


The document root directory where the currently running script resides. Defined in the server configuration file.


"Http_accept"


Accept of the current request: the contents of the header information.


"Http_accept_charset"


Accept-charset of the current request: the contents of the header information. For example: "Iso-8859-1,*,utf-8".


"Http_accept_encoding"


Accept-encoding of the current request: the contents of the header information. For example: "gzip".


"Http_accept_language"


Accept-language of the current request: the contents of the header information. For example: "en".


"Http_connection"


Connection of the current request: the contents of the header information. For example: "Keep-alive".


"Http_host"


The contents of the Host: header information for the current request.


"Http_referer"


Link to the URL address of the previous page of the current page. Not all user agents (browsers) will set this variable, and some can also modify http_referer manually. Therefore, this variable is not always true and correct.


"Http_user_agent"


User-agent of the current request: the contents of the header information. The string indicates the information for the user agent accessing the page. A typical example is: mozilla/4.5 [en] (X11; U Linux 2.2.9 i586). You can also use Get_browser () to get this information.


"HTTPS"


If the script is accessed through the HTTPS protocol, it is set to a Non-empty value.


"REMOTE_ADDR"


Browsing the IP address of the user of the current page.


"Remote_host"


The host name of the user who is browsing the current page. The reverse domain name resolution is based on the user's remote_addr.


Note: The WEB server must be configured to establish this variable. For example, Apache needs to have hostnamelookups on in httpd.conf. See Gethostbyaddr ().


"Remote_port"


The port to use when the user connects to the server.


"Script_filename"


The absolute path name of the current execution script.


Note: If the script is executed in the CLI, as a relative path, such as file.php or. /file.php,$_server[' Script_filename ' will contain the relative path specified by the user.





"Server_admin"


This value indicates the Server_admin parameter in the Apache server configuration file. If the script is running on a virtual host, the value is the value of that virtual host.


"Server_port"


The port used by the server. The default is "80". If you are using SSL secure connections, this value is the HTTP port that the user sets.


"Server_signature"


A string containing the server version and the virtual host name.


"Path_translated"


The basic path of the file system (not the document root) that contains the current script. This is the result of a virtual to real-path image of the server.


Note: After the PHP 4.3.2, path_translated in the Apache 2 SAPI mode is no longer the same implied assignment as Apache 1, but if Apache does not generate this value, PHP generates and puts its value into the Script_filename service Device constants. This modification complies with the CGI specification and path_translated only exists under conditions defined by PATH_INFO.


Apache 2 users can use Acceptpathinfo on in httpd.conf to define PATH_INFO.


"Script_name"


The path that contains the current script. This is useful when the page needs to point to itself. __FILE__ contains the absolute path and file name of the current file (for example, include files).


"Request_uri"


The URI required to access this page. For example, "/index.html".


"Php_auth_digest"


When running as an Apache module, this variable is set to the "Authorization" HTTP header content sent by the client (for further authentication) during HTTP Digest authentication.


"Php_auth_user"


When PHP is running in Apache or IIS (PHP 5 is ISAPI) module mode, and is using the HTTP authentication function, this variable is the user entered user name.


"PHP_AUTH_PW"


When PHP is running in the Apache or IIS (PHP 5 is ISAPI) module mode, and is using the HTTP authentication function, this variable is the user entered the password.


"Auth_type"


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





Environment variable: $_env


Note: Used in PHP 4.1.0 and later versions. Previous versions, using the $HTTP _env_vars.


When the parser runs, these variables are converted from environment variables to PHP global variable Namespaces (namespace). Many of them are determined by the system that PHP runs. The complete list is not possible. Check your system's documentation to determine its specific environment variables.


Other environment variables, including CGI variables, are listed here, whether PHP is run as a server module or as a CGI processor.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_env in a function or method; To access it, just as with $HTTP _env_vars.


$HTTP _env_vars contains the same information, but not an automatic global variable (note: $HTTP _env_vars and $_env are different variables that PHP handles differently).


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_env and $HTTP _env_vars arrays are separated. For information, please refer to the Security section for the use of the Register Globals. These individual global variables are not automatic global variables.


HTTP Cookies:$_cookie


Note: Used in PHP 4.1.0 and later versions. Previous versions, using the $HTTP _cookie_vars.


An array of variables passed through an HTTP cookie. is an automatic global variable.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_cookie in a function or method; To access it, just as with $HTTP _cookie_vars.


$HTTP _cookie_vars contains the same information, but not an automatic global variable (note: $HTTP _cookie_vars and $_cookie are different variables that PHP handles differently).


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_cookie and $HTTP _cookie_vars arrays are separated. For information, please refer to the Security section for the use of the Register Globals. These individual global variables are not automatic global variables.


HTTP Get variable: $_get


Note: Used in PHP 4.1.0 and later versions. Previous versions, using the $HTTP _get_vars.


An array of variables passed through the HTTP get method. is an automatic global variable.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_get in a function or method; To access it, just as with $HTTP _get_vars.


$HTTP _get_vars contains the same information, but not an automatic global variable (note: $HTTP _get_vars and $_get are different variables that PHP handles differently).


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_get and $HTTP _get_vars arrays are separated. For information, please refer to the Security section for the use of the Register Globals. These individual global variables are not automatic global variables.


HTTP POST Variable: $_post


Note: Used in PHP 4.1.0 and later versions. Previous versions, using the $HTTP _post_vars.


An array of variables passed through the HTTP POST method. is an automatic global variable.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_post in a function or method; To access it, just as with $HTTP _post_vars.


$HTTP _post_vars contains the same information, but not an automatic global variable (note: $HTTP _post_vars and $_post are different variables that PHP handles differently).


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_post and $HTTP _post_vars arrays are separated. For information, please refer to the Security section for the use of the Register Globals. These individual global variables are not automatic global variables.


HTTP File Upload variable: $_files


Note: Used in PHP 4.1.0 and later versions. Previous versions, using the $HTTP _post_files.


An array of uploaded file items passed through the HTTP POST method. is an automatic global variable.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_files in a function or method; To access it, just as with $HTTP _post_files.


$HTTP _post_files contains the same information, but is not an automatic global variable (note that PHP treats $HTTP _post_files and $_files as different variables).


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_files and $HTTP _post_files arrays are separated. For information, please refer to the Security section for the use of the Register Globals. These individual global variables are not automatic global variables.


Request variable: $_request


Note: Used in PHP 4.1.0 and later versions. Previous version, no equivalent array.


Note: Before PHP 4.3.0, $_files is also included in the $_request array.


This associative array contains all the contents of $_get,$_post and $_cookie.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_request in a function or method; To access it.


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_request array is detached. For information, please refer to the Security section for the use of the Register Globals. These individual global variables are not automatic global variables.


Session variable: $_session


Note: Used in PHP 4.1.0 and later versions. Previous versions, using the $HTTP _session_vars.


An array containing the session variables in the current script. See the session function documentation for more information.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. You do not need to use global $_session in a function or method; To access it, just as with $HTTP _session_vars.


$HTTP _session_vars contains the same information, but is not an automatic global variable (note that PHP treats $HTTP _session_vars and $_session as different variables).


If the register_globals directive is set, these variables are also available in all scripts, that is, the $_session and $HTTP _session_vars arrays are separated. For information, please refer to the Security section for the use of the Register Globals. These individual global variables are not automatic global variables.


Global variables: $GLOBALS


Note: $GLOBALS is applicable in PHP 3.0.0 and later versions.


An array of all defined global variables. The variable name is the index of the array.


This is a "superglobal", or it can be described as an automatic global variable. This simply means that it works in all scripts. The global $GLOBALS is not required in a function or method; To access it.


Previous error message: $php _errormsg


$php _errormsg is a variable that contains the contents of the last error message generated by PHP. The variable is not valid until an error occurs and the Track_errors option is turned on (closed by default).


Copy Code code as follows:

<?php
function getserveraddress () {
if ($_server[' server_addr ']) {
Return $_server[' server_addr '];
}

$ifconfig = Shell_exec ('/sbin/ifconfig eth0 ');
Preg_match ('/addr: [\d\.] +)/', $ifconfig, $match);

return $match [1];
}
?>

Copy Code code as follows:

<?php
function getserveraddress () {
if ($_server[' server_addr ']) {
Return $_server[' server_addr '];
}

$ifconfig = Shell_exec ('/sbin/ifconfig eth0 ');
Preg_match ('/addr: [\d\.] +)/', $ifconfig, $match);

return $match [1];
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.