group-icon
PHP Programming
Group for all things PHP, Coding Help, Problems and Solutions
101 Members
Join this group to post and comment.
Shruthi Pillai
Shruthi Pillai
Information Technology
29 Jan 2019

Superglobals in php

Superglobals are specially-defined array variables in PHP that make it easy for you to get information about a request or its context. The superglobals are available throughout your script.  They are mainly used to store and get information from one page to another etc in an application. 

$GLOBALS - It is a superglobal variable which is used to access global variables from anywhere in the PHP script. 

$_SERVER - It is a PHP super global variable that stores the information about headers, paths and script locations.  

$_REQUEST - It is a superglobal variable which is used to collect the data after submitting a HTML form. 

$_POST and $_GET - these are super global variables used to collect data from the HTML form after submitting it. 

AdhikariHarika Reshma
AdhikariHarika Reshma
Computer Science
1mo ago

The content is easy to understand.Thank you for explaining it in a simple way.


DHIRAJ LOTLIKAR
DHIRAJ LOTLIKAR
Information Technology
1mo ago

Superglobals are the variables which are already created by the PHP engine for us. So some of the global variables are $GLOBAL, $_POST, $_GET, $_COOKIE, $_SESSION, $_SERVER, $FILES, $_REQUEST,and $_ENV. Lets check each one of them individually. 

$GLOBAL is used to access global variable where ever you need the variable, maybe in function, in loops or PHP script.

For example,

$x=5;

function example(){
$y=10;

echo $GLOBALS['x'];

}

example();

?>

The output for the above code is 5.

$_POST and $_GET are used to get information send in the page request. Parameters send in the Url are made available by $_GET . 

$_POST is used to send data to the script and used mainly for confidential data like username or password.

$_REQUEST is the amalgam of $_POST and $_GET data. $_SESSION and $_COOKIE are used for creating sessions and cookies respectively. Following is example of session,

session_start();
$_SESSION["videogame"] = "Battletoads";
?>
Go to page 2

$_SERVER is a superglobal store the information of the web server and the request made to it.