Superglobals were introduced in PHP 4.1.0. They are built-in variables that are always available in all scopes. You can access them from any function, class or file without having to do anything special.

The PHP superglobal variables are:

  1. $GLOBALS
  2. $_SERVER
  3. $_REQUEST
  4. $_POST
  5. $_GET
  6. $_FILES
  7. $_ENV
  8. $_COOKIE
  9. $_SESSION

$GLOBALS is used to access global variables from anywhere in the PHP script. PHP stores all global variables in an array called $GLOBALS[index].

$_SERVER holds information about headers, paths, and script locations.

$_REQUEST is used to collect data after submitting an HTML form.

$_POST is used to collect form data after submitting an HTML form with method="post".

$_GET is used to collect form data after submitting an HTML form with method="get".

PHP $_SERVER Global Variable

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

$_SERVER['SERVER_ADDR']: Returns the IP address of the host server

$_SERVER['SERVER_NAME']: Returns the name of the host server

$_SERVER['REQUEST_METHOD']: Returns the request method used to access the page

$_SERVER['QUERY_STRING']: Returns the query string if the page is accessed via a query string

$_SERVER['HTTP_HOST']: Returns the Host header from the current request

$_SERVER['HTTPS']: Is the script queried through a secure HTTP protocol

$_SERVER['REMOTE_ADDR']: Returns the IP address from where the user is viewing the current page

$_SERVER['REMOTE_HOST']: Returns the Host name from where the user is viewing the current page

$_SERVER['REMOTE_PORT']: Returns the port being used on the user's machine to communicate with the web server

$_SERVER['SERVER_PORT']: Returns the port on the server machine being used by the web server for communication

$_SERVER['SCRIPT_NAME']: Returns the path of the current script

$_SERVER['SCRIPT_URI']: Returns the URI of the current page