PHP 5 Global Variables - Superglobals

There are so many predefined global variable in php. It can be accessible from any function, class or file without you having to create them first. Global variable were introduced from php4.1 which is always available in all scope.

Super Global variables are an array variable in PHP

List of PHP superglobal variables are given below:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
  • PHP $GLOBALS (super global) variable

    $GLOBAL is a php super global variable which contains all global variables in php script, including other superglobals.

    Example -

    PHP $_SERVER

    $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.

    Example -

    PHP $_REQUEST

    When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the tag. In this example, we point to this file itself for processing form data. If you wish to use another PHP file to process form data, replace that with the filename of your choice. Then, we can use the super global variable $_REQUEST to collect the value of the input field:

    Example -

    PHP $_POST

    PHP $_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.

    The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the tag. In this example, we point to the file itself for processing form data. If you wish to use another PHP file to process form data, replace that with the filename of your choice. Then, we can use the super global variable $_POST to collect the value of the input field:

    Example -