$_SERVER in PHP

What is $_SERVER in PHP

$_SERVER is global variable  in PHP ,an array containing information such as headers, paths, and script locations in PHP. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these.

Syntax : $variable = $_SERVER[\’Request type\’];

$_SERVER contain various  important elements which request different details of the page .

Type Of Server Request Request  Details
$_SERVER[\’PHP_SELF\’] Gives filename of the currently executing script
$_SERVER[\’GATEWAY_INTERFACE\’] Gives version of the Common Gateway Interface (CGI) the server is using
$_SERVER[\’SERVER_ADDR\’] Gives IP address of the host server
$_SERVER[\’SERVER_NAME\’] Gives name of the host server (such as www.sitee.in)
$_SERVER[\’SERVER_SOFTWARE\’] Gives server identification string (such as Apache)
$_SERVER[\’SERVER_PROTOCOL\’] Gives name and revision of the information protocol (such as HTTP/1.7)
$_SERVER[\’REQUEST_METHOD\’] Gives request method used to access the page (such as GET)
$_SERVER[\’REQUEST_TIME\’] Gives timestamp of the start of the request (such as 1478526369)
$_SERVER[\’QUERY_STRING\’] Gives query string if the page is accessed via a query string
$_SERVER[\’HTTP_ACCEPT\’] Gives Accept header from the current request
$_SERVER[\’HTTP_ACCEPT_CHARSET\’] Gives Accept_Charset header from the current request (such as utf-8)
$_SERVER[\’HTTP_HOST\’] Gives Host header from the current request
$_SERVER[\’HTTP_REFERER\’] Gives complete URL of the current page (not reliable because not all user-agents support it)
$_SERVER[\’HTTPS\’] Is script queried through a secure HTTP protocol
$_SERVER[\’REMOTE_ADDR\’] Gives IP address from where the user is viewing the current page
$_SERVER[\’REMOTE_HOST\’] Gives Host name from where the user is viewing the current page
$_SERVER[\’REMOTE_PORT\’] Gives port being used on the user\’s machine to communicate with the web server
$_SERVER[\’SCRIPT_FILENAME\’] Gives absolute path name of the currently executing script
$_SERVER[\’SERVER_ADMIN\’] Gives value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host)
$_SERVER[\’SERVER_PORT\’] Gives port on the server machine being used by the web server for communication (such as 40)
$_SERVER[\’SERVER_SIGNATURE\’] Gives server version and virtual host name which are added to server-generated pages
$_SERVER[\’PATH_TRANSLATED\’] Gives file system based path to the current script
$_SERVER[\’SCRIPT_NAME\’] Gives path of the current script
$_SERVER[\’SCRIPT_URI\’] Gives URI of the current page
Scroll to Top