Global variables in PHP

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[ ]
Super global variables in PHP
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.


$_POST[ ]:

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


See also to understand more about GET and POST


Session variable is also global and it is global throughout the program file and virtual directory.



Same like sessions they are also global for the whole virtual directory you can easily create, update, delete and access them anywhere.

Read more about cookies.


This variable is also same like GET and POST and used to collect values that are submitted from HTML form. See the example of Ajax where we collect data using request super global variable

$_SERVER[ ]:

These variables are mostly used to know the client or server information like IP address of server or HOST , host or server name etc.



This variable makes simple local variables global.

Display PHP globals
Display PHP globals