PHP – $_SERVER SuperGlobal Variable
In PHP $_SERVER is also a superglobal variable just like $_POST , $_GET and $_GLOBALS . Superglobals are accessible from anywhere in php code . $_SERVER is also a pre-defined variable in php to get environmental information .
Syntax of $_SERVER variable is as much as other global variable . Only capital letters are allowed in it . Variable values are also pre-defined for this variable .
In this example , value SCRIPT_NAME is used for get script name (/php/index.php).
In $_SERVER variable all values are also pre-defined and it must be written in capital letters . All of values are as follows.
All of these elements are pre-defined in this global variable .
For example if you use this variable and want to get host name the value [‘HTTP_HOST‘] is used . And the code to access is
<html> <head></head> <body> <?php echo "Host Name is ".$_SERVER['HTTP_HOST']; ?> </body> </html>
Result of this code is
Different elements are used for different purpose . In this variable ,elements are also pre defined as you read above . And one more thing is that variable name and element name must be in capital letters .