Home > Backend Development > PHP Tutorial > Detailed explanation of PHP predefined variable examples

Detailed explanation of PHP predefined variable examples

怪我咯
Release: 2023-03-07 16:52:02
Original
3716 people have browsed it

What are PHP predefined variables?

In PHP programming, you often encounter information that requires the use of the address bar, such as domain names, visited URLs, URL parameters, etc. In this case, you can use the predefined variables provided by PHP , through these predefined variables, information such as the user's session, the user's operating system environment and the local operating system environment can be obtained. This information is stored in the predefined variable $_SERVER. (Detailed explanation of PHP predefined constant examples)

The predefined variable $_SERVER

##$_SERVER is a variable that contains information such as An array of header information (header), path (path), and script locations (script locations) and other information. Now I will print $_SERVE to see the content of $_SERVER. The code is as follows;

<?php
echo "<pre class="brush:php;toolbar:false">";
print_r($_SERVER);
?>
Copy after login

Print The results are as follows:

Detailed explanation of PHP predefined variable examples

For specific information about the above parameter information, you can refer to the PHP complete self-study manual:

php super global variables.

What are the predefined variables in php?

The following table is some commonly used predefined variables in PHP. The first few in the table are some information in $_SERVER. If you are interested, you can take a look at the above example

##$_SERVER['REMOTE_HOST']Browse The host name of the user on the current page. Reverse domain name resolution is based on the user's REMOTE_ADDR$_SERVER['REMOTE_PORT'] The user's machine is connected to the Web server Port number used $_SERVER['SCRIPT_FILENAME']The absolute path of the currently executing script. Note that if the script is executed from 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 number of the server where the script is currently running, the default is 80. If an SSL secure connection is used, this value is the HTTP port set by the user$_SERVER['SERVER_SIGNATURE']A string containing the server version and virtual host name. $_SERVER['DOCUMENT_ROOT']The document root directory where the currently running script is located. Defined in the server configuration file. $_COOKIEAn array of variables passed to the current script through HTTP Cookies. Most of these cookies are set through the setCookies() function when executing PHP scripts. $_SESSION Contains information related to all session variables. The $_SESSION variable is mainly used for session control and the transfer of values ​​between pages$_POSTContains information related to parameters passed through the POST method, mainly used to obtain data submitted through the POST method$_GET Contains information related to parameters passed through the GET method, mainly used to obtain data submitted through the GET method $GLOBALS is defined by all An array of global variables. The variable name is the index into the array. It can be said to be a super set of all super variables. $_FILESArray of items uploaded to the current script via HTTP POST$_REQUESTContains arrays of $_GET, $_POST and $_COOKIE by default. $_ENV An array of variables passed to the current script through the environment. $php_errormsgPrevious error message$HTTP_RAW_POST_DATA Native POST data$http_response_header HTTP response header$argc The number of parameters passed to the script$argv Argument array passed to the script

The above table is our PHP predefined variables. For details, you can check our PHP Complete Self-Study Manual. After learning the constants and variables of PHP, in the next section, we will learn about "PHP What is the difference between constants and variables?

Name of the variable Description
$_SERVER['SERVER_ADDR'] Currently running script The IP address of the server
$_SERVER['SERVER_NAME'] The host name of the server where the script is currently running. If the program is running on a virtual host, the name is determined by the value set by the virtual host
$_SERVER['REQUERT_METHOD'] The request method used to access the page. Such as GET, HEAD, POST, PUT, etc., if the request method is HEAD, the PHP script will output the header information and then terminate (this means that after any output is generated, there will be no output buffering)
$_SERVER['REMOTE_ADDR'] The IP address of the user browsing the current page

The above is the detailed content of Detailed explanation of PHP predefined variable examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template