$_SERVER is one of the super global variables in PHP. It contains information about headers, server, host and etc. For that, it contains huge list of information with appropriate global indices.
With these global indices, $_SERVER array contains values for the meta variables listed with the specification of common gateway interface. So, while running a PHP script, $_SERVER array will be loaded with the values based on the criteria, like, in which interface the server is running and etc.
Now, we are going to see some of the list of possible indices with $_SERVER array in PHP. And also, we are going to see about the factors based on which these array indices can be categorized.
So, $_server array indices contain information related to the list of following items.
Let us look into the available indices of $_SERVER array, that falls under each of the above list, one by one.
Under this category, we are going to see the available indices of this PHP global array that are used to store information like, accepted language and encoding technique, charset, connection and etc.
All of the above indices of PHP $_SERVER array will be loaded with the values stored in header, while requesting a page from server. And the captions to refer these values with header content, are Host, Connection, Charset, Encoding, Language, respectively.
Added to that, some other array indices in this category, which are used to hold details such as, accepted MIME type, user agent and etc.
$_SERVER array contains indices that hold information about page request is as shown below.
The indices coming under this category will be used widely to create full URL for the current page. For that we can concatenate strings stored into the $_SERVER array with the following array indices.
This category includes set of array indices that are used to store name, address and port of the remote user host, from which the page request is generated. And the corresponding indices are as follows.
And then, it also contains indices for storing authenticated user to access page or to redirect. These array indices are,
HTTP authentication is used to let user to enter the user name and password to access to requested page. Once, the user entered their user name and password, it will be stored into the global variables, $_SERVER[“PHP_AUTH_USER”], $_SERVER[“PHP_AUTH_PW”], respectively.
HTTP authentication can be any one of basic or digest type authentication. If we choose digest type, then, the $_SERVER[“PHP_AUTH_DIGEST”] will be set. And, $_SERVER[“PHP_AUTH_TYPE”] is used to store the type of authentication as selected.
This PHP code tutorial was published on July 29, 2013.