PHP Global Variables

PHP Global Variables

PHP Global Variables

PHP superglobal variables are special variables that are built into the language and are always available, regardless of the scope of the code. These variables are called “superglobal” because they can be accessed from any part of the script, including functions, classes, and methods. Here are some of the most commonly used PHP superglobal variables:

  1. $_GET: This variable contains an associative array of variables passed to the current script via the HTTP GET method. The keys in this array correspond to the names of the input fields in the HTML form that submitted the data.
  2. $_POST: This variable contains an associative array of variables passed to the current script via the HTTP POST method. The keys in this array correspond to the names of the input fields in the HTML form that submitted the data.
  3. $_REQUEST: This variable contains an associative array of variables passed to the current script via the HTTP GET or POST methods. The keys in this array correspond to the names of the input fields in the HTML form that submitted the data.
  4. $_SERVER: This variable contains an array of server and execution environment information, such as the file path of the current script, the host name of the server, and the user agent of the client’s browser.
  5. $_SESSION: This variable contains an associative array of variables that persist across multiple page requests and is used to store user-specific data on the server.
  6. $_COOKIE: This variable contains an associative array of variables that have been stored in cookies on the client’s browser.
  7. $_FILES: This variable contains an associative array of files uploaded to the current script via the HTTP POST method. The keys in this array correspond to the names of the input fields in the HTML form that submitted the data.

By using these superglobal variables, PHP developers can easily access and manipulate data across different parts of their code and between different page requests.

Join To Get Our Newsletter
Spread the love