What is $_SERVER in Php?

$_SERVER is a Super Global variable in Php.

It contains information on headers, paths, and script locations.
Here is a listing.


$_SERVER['PHP_SELF']= Filename of the currently executing script
$_SERVER['GATEWAY_INTERFACE'] Version of Common Gateway Interface (CGI) being used
$_SERVER['SERVER_ADDR']  IP address of the host server
$_SERVER['SERVER_NAME'] Name of the host server.
$_SERVER['SERVER_SOFTWARE'] Server identification string. Maybe Apache x.y
$_SERVER['SERVER_PROTOCOL'] Name and version of protocol HTTP/1.1
$_SERVER['REQUEST_METHOD'] Request method Get or Post.
$_SERVER['REQUEST_TIME'] Timestamp of the start of the request.
$_SERVER['QUERY_STRING'] Query string.
$_SERVER['HTTP_ACCEPT']  Accept header from the current request
The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an in-line image.
More details here
</div> $_SERVER['HTTP_ACCEPT_CHARSET'] Accept_Charset header from the current request (such as utf-8,ISO-8859-1) The Accept-Charset request HTTP header advertises which character set the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice within the Content-Type response header More information here.
The Accept-Charset request HTTP header advertises which character set the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice within the Content-Type response header. Browsers usually don't set this header as the default value for each content type is usually correct and transmitting it would allow easier fingerprinting.
</div> &nbsp; List of content types.
The Content-Type entity header is used to indicate the media type of the resource.
</div> $_SERVER['HTTP_HOST'] Returns the Host header from the current request $_SERVER['HTTP_REFERER'] Returns the complete URL of the page from which the current page was called $_SERVER['HTTPS'] Is the script queried through a secure HTTP protocol $_SERVER['REMOTE_ADDR']  IP address from where the user viewing the page $_SERVER['REMOTE_HOST'] Host name from where the user is viewing the current page $_SERVER['REMOTE_PORT'] Port being used on the user's machine to communicate with the web server $_SERVER['SCRIPT_FILENAME'] Absolute pathname of the currently executing script $_SERVER['SERVER_ADMIN'] Returns the value given to the SERVER_ADMIN directive in the web server configuration file. $_SERVER['SERVER_PORT'] Port on the server machine being used by the web server for communication (such as 80) $_SERVER['SERVER_SIGNATURE']  Server version and virtual host name which are added to server-generated pages $_SERVER['PATH_TRANSLATED'] File system based path to the current script $_SERVER['SCRIPT_NAME'] Path of the current script $_SERVER['SCRIPT_URI'] URI of the current page

 

Use the following code to print a complete list of keys and values in $_SERVER.


<?php
$keys=array_keys($_SERVER);
foreach($keys as $key)
{
$value=$_SERVER[$key];
print "$key = $value<br/>";
}
?>


HTTP_HOST = localhost
HTTP_CONNECTION = keep-alive
HTTP_UPGRADE_INSECURE_REQUESTS = 1
HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
HTTP_DNT = 1
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
HTTP_ACCEPT_ENCODING = gzip, deflate, br
HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.9
PATH = C:\Python27\;C:\Python27\Scripts;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\dotnet\;C:\Android;C:\Windows\System32;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Live\Shared;C:\wamp\bin\php\php5.6.40;C:\ProgramData\ComposerSetup\bin;C:\Program Files\Git\cmd;C:\Users\Champak Roy\.dotnet\tools
SystemRoot = C:\Windows
COMSPEC = C:\Windows\system32\cmd.exe
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
WINDIR = C:\Windows
SERVER_SIGNATURE =
Apache/2.4.37 (Win64) PHP/7.2.14 Server at localhost Port 80

SERVER_SOFTWARE = Apache/2.4.37 (Win64) PHP/7.2.14
SERVER_NAME = localhost
SERVER_ADDR = ::1
SERVER_PORT = 80
REMOTE_ADDR = ::1
DOCUMENT_ROOT = C:/wamp/www
REQUEST_SCHEME = http
CONTEXT_PREFIX =
CONTEXT_DOCUMENT_ROOT = C:/wamp/www
SERVER_ADMIN = wampserver@wampserver.invalid
SCRIPT_FILENAME = C:/wamp/www/globals/servervars.php
REMOTE_PORT = 37109
GATEWAY_INTERFACE = CGI/1.1
SERVER_PROTOCOL = HTTP/1.1
REQUEST_METHOD = GET
QUERY_STRING =
REQUEST_URI = /globals/servervars.php
SCRIPT_NAME = /globals/servervars.php
PHP_SELF = /globals/servervars.php
REQUEST_TIME_FLOAT = 1552463291.539
REQUEST_TIME = 1552463291

Leave a Reply