PHP Superglobal - $_SERVER with Examples

PHP Superglobal - $_SERVER with Examples


$_SERVER is one of the supergobal variables.$_SERVER is an array which holds information of headers, paths, script locations. Web server creates the entries in the array. This is not assured that every web server will provide similar information, rather some servers may include or exclude some information which are not listed here.

For Example :

Ouput : localhost   

              localhost 

The following table contains a data list that might be stored in the $_SERVER variable.

Code Description
$_SERVER['PHP_SELF'] Contains the file name of the currently running script.
$_SERVER['GATEWAY_INTERFACE'] Contains the version of the Common Gateway Interface being used by the server.
$_SERVER['SERVER_ADDR'] Contains the server's IP address.
$_SERVER['SERVER_NAME'] Contains the host name of the server.
$_SERVER['SERVER_SOFTWARE'] Contains the server identification string.
$_SERVER['SERVER_PROTOCOL'] Contains the name and revision of the version protocol.
$_SERVER['REQUEST_METHOD'] Contains the request method used to access the page.
$_SERVER['REQUEST_TIME'] Contains the timestamp of the start of the request.
$_SERVER['QUERY_STRING'] Contains the query string if the page was accessed using a query.
$_SERVER['HTTP_ACCEPT'] Contains the Accept header from the current request.
$_SERVER['HTTP_ACCEPT_CHARSET'] Contains the Accept_charset header from the current request.
$_SERVER['HTTP_HOST'] Contains the Host header from the current request.
$_SERVER['HTTP_REFERER'] Contains the URL of the current page.
$_SERVER['HTTPS'] Contains information regarding if the script was queried using a secure protocol.
$_SERVER['REMOTE_ADDR'] Contains the IP address from which the user is accessing the current page.
$_SERVER['REMOTE_HOST'] Contains the host name from where the user is accessing the current page.
$_SERVER['SCRIPT_FILENAME'] Contains the path of the script that's currently running.
$_SERVER['SERVER_ADMIN'] Contains the value given to SERVER_ADMIN in the configuration file.
$_SERVER['SERVER_PORT'] Contains the port on the web server being used for communication.
$_SERVER['SERVER_SIGNATURE'] Contains the server version and virtual host name that are added to server-generated pages.
$_SERVER['PATH_TRANSLATED'] Contains the file-system path to the current script.
$_SERVER['SCRIPT_NAME'] Contains the path to the current script.
$_SERVER['SCRIPT_URI'] Contains the URL of the current script.