PHP Server Variables

Defining Server Variables in PHP

PHP have some predefine variable in which one of the most important type of variables are server variables. Basically Server variable which is define as $_SERVER is an array, which contain the information about headers, paths, browser information, the IP address, and which web page the visitor came from etc. The information in this array are created and store by the web server. This is also possible that some of the information will not provides by the server.
You can get all the information store in server variable array with the help of foreach loop.


<?php
foreach($_SERVER as $key_name => $key_value)

 {

print $key_name . " = " . $key_value . "<br>";

}

?>

Syntax :
$_SERVER['Server_Variable'];
For example :
$display = $_SERVER['PHP_SELF'];
Display the opened page name.
$display= $_SERVER['SERVER_NAME'];
Display the server name (website name) in our website it display the learninghints.com.
$display= $_SERVER['SERVER_SOFTWARE'];
Display the the software of webserver. in our case Apache