Quick Reach
$_SERVER Introduction
In PHP $_SERVER is a superglobal, an array which contains different information like headers, path, Server name, Server software, Server protocol, IP address, and few others. However you may access all or not depends on your hosting or web server where your site is hosted.
$_SERVER Example
Below is a list of few useful $_SERVER variables that can be written in PHP program to return values, some of which can prove to be really useful to know about:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?php
echo “Requested URL is: “.$_SERVER[‘REQUEST_URI’].“<BR>”;
echo “Which URL: “.$_SERVER[‘PHP_SELF’].“<BR>”;
echo ” Get IP Address: “.$_SERVER[‘SERVER_ADDR’].“<BR>”;
echo “Server Name: “.$_SERVER[‘SERVER_NAME’].“<BR>”;
echo “Request Timeout: “.$_SERVER[‘REQUEST_TIME’].“<BR>”;
echo “Document root (Physical path): “.$_SERVER[‘DOCUMENT_ROOT’].“<BR>”;
echo “Script (Physical path): “.$_SERVER[‘SCRIPT_FILENAME’].“<BR>”;
echo “Server Admin: “.$_SERVER[‘SERVER_ADMIN’].“<BR>”;
echo “Server Port: “.$_SERVER[‘SERVER_PORT’].“<BR>”;
?>
|
One example where $_SERVER is used to get current URL is given here
Leave A Comment?