Home >Backend Development >PHP Problem >What are the global variables in php
php global variables include "$_SERVER", "$_GET", "$_POST", "$_FILES", "$_COOKIE", "$_SESSION" and "$_REQUEST". 1. "$_SERVER" is an associative array containing the server and environment information for the current PHP script running; 2. "$_GET" is an associative array containing all parameters sent to the current script through the GET method; 3. " $_POST" and so on.
The operating environment of this tutorial: windows10 system, php8.1.3 version, DELL G3 computer.
PHP is a widely used server-side scripting language used to develop dynamic websites and applications. in PHP , there are some special variables called global variables (SuperGlobals) that can be accessed and used throughout the code. These global variables provide a lot of useful information and functions to facilitate the developer's work. In this article we will discuss Some global variables in PHP.
1. $_SERVER
$_SERVER variable is a variable containing the server and the current PHP An associative array of environment information for the script to run in. It contains information such as the request method (GET, POST, etc.), the file path of the script, and the IP of the server. Address and other information. This information is useful for processing user requests and generating dynamic content.
2. The $_GET
$_GET variable is an associative array containing all parameters sent to the current script via the GET method. GET request takes parameters as URL is sent as part of the array, so these parameters can be accessed and processed through this array. $_GET["parameter_name"] will return the value of the specified parameter.
3. The $_POST
$_POST variable is an associative array containing all parameters sent to the current script via the POST method. POST request takes parameters as HTTP is sent as part of the message, so these parameters do not appear in the URL. $_POST["parameter_name"] will return the value of the specified parameter.
4. The $_FILES
$_FILES variable is an associative array containing all files uploaded to the current script via the POST method. For file upload forms, $_FILES["file_name"] Will contain information about the file such as file name, temporary file path, etc.
5. $_COOKIE
$_COOKIE variable is an associative array containing all cookies sent to the current script via HTTP cookies. cookies It is a small text file that the server sets in the client browser to store user preferences, session information, etc. These can be accessed and processed via $_COOKIE["cookie_name"] cookies.
6. The $_SESSION
$_SESSION variable is an associative array containing all session variables stored in the current session. Session variables are variables that are stored and accessed continuously between different pages. Using $_SESSION Variables, the session must be started using the session_start() function.
7. $_REQUEST
$_REQUEST variable is an associative array containing all parameters sent to the current script through the GET or POST method. It combines $_GET, $_POST and The value in the $_COOKIE array, so you can use this variable to get any type of parameter.
These are some global variables commonly used in PHP, which provide convenient ways to access and handle user requests and environmental information. Understanding and skillfully using these variables allows developers to be more efficient and flexible PHP Programming .
The above is the detailed content of What are the global variables in php. For more information, please follow other related articles on the PHP Chinese website!