PHP pre-defined constants & variables

Source: Internet
Author: User

In PHP, you can use predefined constants to obtain information from PHP, which is commonly used in predefined constants as shown in the following table.

Constant name Function
_file_ Default constants, PHP program file names
_line_ Default constants, number of PHP program lines
Php_version Built constants, versions of PHP programs, such as 3.0.8_dev
Php_os The built constant, which executes the PHP parser's operating system name, such as Windows
TRUE The constant is a truth value (TRUE)
FALSE The constant is a false value (FALSE)
Null A null value
E_error This constant refers to the most recent error where
E_warning This constant refers to the nearest warning.
E_parse This constant refers to a potential problem with the parsing syntax
E_notice The constant is an unusual hint, but not necessarily the wrong place.

Predefined variables in PHP that can be used to obtain information about user sessions, the environment of the user's operating system, and the environment of the local operating system, as shown in the following table of predefined variables.

The name of the variable Description
$_server[' Server_addr '] The IP address of the server where the script is currently running
$_server[' 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 by the virtual host

$_server[' Request_method ']

The request method when the page is accessed. such as, POST, put, etc., if the request is head,php the script will abort after the output header information (which means that no output buffers are available after any output has been generated)

$_server[' REMOTE_ADDR '] Browsing the current page user's IP address
$_server[' Remote_host '] The host name of the user who is browsing the current page. Reverse domain name resolution based on the user's remote_addr
$_server[' Remote_port '] The port used by the user when connecting to the server
$_server[' Script_filename ']

The absolute path name of the currently executing script. Note that 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 user-specified relative path

$_server[' Server_port ']

The port used by the server, which defaults to 80. If SSL secured connection is used, this value is the HTTP port set by the user

$_server[' Server_signature '] A string containing the server version and the virtual host name
$_server[' Document_root '] The document root directory where the script is currently running. Defined in the server configuration file
$_cookie

The information passed to the script via HttpCookie. Most of these cookies are set by the Setcookie () function when the PHP script is executed.

$_session

Contains information about all session variables. The $_session variable is primarily used for session control and is worth passing between pages

$_post

Contains information about the parameters passed through the Post method. Used primarily to obtain data submitted via the Post method

$_get

Contains information about the parameters passed by the Get method. Used primarily to obtain data submitted through the Get method

$GLOBALS

An array that consists of all defined global variables. The variable name is the index of the array. It can be called a super collection of all the super variables.

PHP pre-defined constants & variables

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.