What are the predefined variables in php?
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
