PHP Super Global Variables

Programming

What are the PHP super global variables

PHP Super Global Variables – Some predefined variables in PHP are “superglobals,” meaning they are always available, irrespective of the scope so you can access them from any method, class, or file without having to do anything different.

They are specially defined PHP array variables which make it easy for you to obtain information about an application or its context. The superglobals are all over your file. These variables can be accessed from any function, class, or file without having to do some special tasks like defining some global variables, etc. They are primarily used in an application for processing and accessing information from one website to another etc. The global variable from php4.1 was added and is still available in all contexts. Super Global variables are a vector for the PHP list.

The list of superglobals variables in PHP is given below:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
PHP Super Global Variables

$GLOBALS – Contains a reference for each variable that is currently accessible within the script’s global scope. This array’s keys are named for global variables. PHP stores all of the global variables in $GLOBALS list where index contains the name of the global variable that can be accessed.

$_SERVER – It’s a superglobal PHP variable that stores the headers, routes, and script location information. Many of such components are used to extract the details from the $_SERVER superglobal array.

$_REQUEST – After submitting HTML Form, $_REQUEST is used to access the data. The process of formation will either be ‘GET’ or ‘POST’. Here is a basic example where I apply a form that is pointing to itself for GET system data processing.

$_POST – PHP $_POST is a PHP super global variable that uses method=”post “to gather form data after uploading an HTML form Furthermore $_POST is commonly used to transfer variables.

$_GET – It is used with method=’get’ to extract value from a form(HTML script) submitted. Data received from the method=’get’ type is available to everyone (it appears on the URL bar of the browser).

$_FILES – The Superglobal $_FILES describes the data accessible from uploads of HTTP POST files to a PHP script. The current favorite way to manage imported data in PHP is by using $_FILES.

$_ENV – The $_ENV Superglobal reflects data accessible from the environment PHP is operating in to a PHP file.

$_COOKIE – An associative array of variables transferred through HTTP cookies into the current file.

$_SESSION – An associative array that includes session variables that are required for the current file.