PHP 7 Superglobal Variables

PHP does not support global variables, certain internal variables treat like global variables. Those variables are called Superglobal variables.

These are the following superglobal variables.


GET method converts the name/value of form data in query string and append to the requested page.

Example -

$_GET[] array retrieve variables from the query string or URL.
Like - $_GET['name'] contains value 'john' and $_GET['age'] contains value 32.

As GET method is visible to everyone in the url so this is not secure and not preferred to send sensitive information.


POST method embedded the form name/value data and send in HTTP headers. So it is not visible in the requested url and more secure than GET method. The $_POST[] array retrieves all the sent information.

Example -

$_POST['name'] and $_POST['age'].


Cookie is used to make the data persistent across request, means we can use the data store in cookie across different pages.
setcookie() function is used to set the data and store in the browser.

Example -

setcookie('username', $username, time()+20000, '/');

In the above line username is the name of cookie to be set, $username has the value of the username cookie and time()+20000 sets the expiration time.


A PHP session stores data on the server rather than user's computer.
In PHP, the session_start() function is used to create a client session and generates a session id.

Example -

$_SESSION['userid'] = '122';
$_SESSION['department'] = 'software';


It stores the information about web server and execution environment. The entries in this array are created by the web server.

Example -

echo $_SERVER['SERVER_NAME']."<br>";
echo $_SERVER['HTTP_HOST']."<br>";
echo $_SERVER['PHP_SELF']."<br>";

Output -

echo $_SERVER['HTTP_HOST']."
"; echo $_SERVER['PHP_SELF']."
"; ?>