Global variables in PHP

In programming languages, global variables are those which are accessible everywhere in the program. There are collections of super global variables in PHP which are always being accessible in the same PHP file.

Superglobals in PHP:

$_GET[ ]

$_POST[ ]

$_SESSION[ ]

$_COOKIES[ ]

$_SERVER[ ]

$_REQUEST[ ]

$GLOBAL

Super global variables in PHP

$_GET[ ]:

These type of variables are used to collect values which are submitted from a form using method = GET. It is always global through the program file and we can easily access it anywhere in the program.

1

2

3

4

5

6

7

8

9

<form action="#"method="GET">

<input type="text"name="user"/>

<input type="submit"value="Click Me"/>

<?php

If(isset($_GET['user'])){

echo$_GET[‘user’];

}

?>

$_POST[ ]:

This is also equal to get super global variables this is used when method have method=POST.