PHP superglobals are predefined variables that are available in all scopes of the script. They can be used to represent data coming from URLs, HTML forms, Cookies, Sessions. etc. They were firstly introduced in PHP 4.1.
The PHP superglobals are:
The PHP $_GET is a superglobal variable that is used to submit an HTML form with the
get method. It is an array of variables passed via the URL parameters. It is populated for all requests with a query string.
The above example is a simple HTML form that submits a form with the
get method whose values can be accessed via the
$_POST is a superglobal variable that is used to submit an HTML form with the
post method. Unlike the
$_GET superglobal, the information is not stored in the URL.
The above example is a simple HTML form that submits a form with the post method whose values can be accessed via the
The PHP $_SERVER is a superglobal that stores information about the headers, paths and location of a PHP script. This variable holds an array of values which are created by the web server. The following include some of the available entries:
- $_SERVER['SERVER_NAME'] - This holds the name of the server which the site was hosted.
- $_SERVER['PHP_SELF'] - This holds the name of the filename of the currently executed PHP script.
- $_SERVER['PHP_HOST'] - This holds the header of the host of the current request if it has any.
- $_SERVER['SCRIPT_NAME'] - This file path of the currently executed script.
- $_SERVER['REMOTE_ADDR'] - This holds the IP address from which the user is currently viewing the page.
The above example uses the $_SERVER variable to output the name of the server, the filepath and filename of the current PHP script.
$_REQUEST is a superglobal that contains the data of
$_COOKIE by default.
The above example shows how to use the $_REQUEST variable to get data from both the