PHP Superglobals are always accessible regardless of their scope, i.e., we can access them from any function, class or a file without even declaring them. Superglobals are available in all scopes throughout a script. There is no need to do global $variable; to access then within functions or methods. The PHP Superglobals represent data coming from URLs, HTML forms, cookies, sessions, and the Web server itself.
Following are the Superglobals in PHP:
-
$_GET – is used to collect the data from the form while submitting an HTML from with get method. It is also used to collect data which is sent in the url.
-
$_POST - is used to collect the data from the form while submitting an HTML from with post method. It is also used to pass variables.
-
$_REQUEST – is used to collect data after submitting an HTML form. The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms.
-
$_SERVER – is an array containing information such as headers, paths, and script locations. Entries in this array are created by the web server
List of important elements that can go inside $_SERVER:
Element/Code |
Description |
$_SERVER['PHP_SELF']
|
Returns the filename of the currently executing script
|
$_SERVER['SERVER_PORT']
|
Returns the port on the server machine being used by the web server for communication (such as 80)
|
$_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['GATEWAY_INTERFACE']
|
Returns the version of the Common Gateway Interface (CGI) the server is using
|
$_SERVER['SERVER_ADDR']
|
Returns the IP address of the host server
|
$_SERVER['SERVER_NAME']
|
Returns the name of the host server
|
$_SERVER['SERVER_PROTOCOL']
|
Returns the name and revision of the information protocol (such as HTTP/1.1)
|
$_SERVER['REQUEST_METHOD']
|
Returns the request method used to access the page (such as POST)
|
$_SERVER['REQUEST_TIME']
|
Returns the timestamp of the start of the request
|
$_SERVER['HTTP_ACCE]
|
Returns the Accept header from the current request
|
0 Comment(s)