$_SERVER is an Array that stores information about the server PHP is running on, such as headers, paths, and script locations. The entries in this array are created by the web server.
The $_SERVER Array is a 'superglobal' variable. This means that it is available in all scopes throughout a script, you can access it directly within functions or classes.
- To access an element of the superglobal $_SERVER array you can use the fallowing syntax:

- 'INDEX' represents the name of the superglobal element to be accessed, it must be written in uppercase and within quotes.
  For example, to display the domain name where the script runs:
Here are some of the most used variables of the superglobal $_SERVER array:
- Let's see some examples with some of this $_SERVER variables.

1. Get the visitor's ip

echo $ip;

2. Get directory name from the URL address of the php script

// for example, if the URL address of the php script is:  http://www.marplo.net/php-mysql/index.php?id=28
$adr = $_SERVER['PHP_SELF'];
$dir = dirname($adr);
echo $dir;                 // /php-mysql

3. Get current page full URL in PHP

// check for https
$protocol = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
// sets the full address
$url = $protocol. $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI'];

echo $url;

- A complete list with the superglobal $_SERVER Array you can find at the oficial page: Superglobal $_SERVER.

Daily Test with Code Example

Which tag is used to add definition lists into a <dl> element?
<dt> <dd> <li>
  <dd> - Hyper Text Markup Language</dd>
  <dd> - Language for web pages</dd>
Which CSS property can hide an element on page, letting an empty space in its place?
display position visibility
#id {
  visibility: hidden;
Click on the event which is triggered when the mouse clicks on an object.
onclick onmouseover onfocus
document.getElementById("id").onclick = function(){
Indicate the PHP variable that contains the contents of both $_GET, $_POST, and $_COOKIE arrays.
if(isset($_REQUEST["id"])) {
  echo $_REQUEST["id"];
Superglobal $_SERVER Array

Last accessed pages

  1. Zuma Deluxe (37883)
  2. Ajax-PHP File Manager (3911)
  3. innerHTML and outerHTML to Get and Replace HTML content (13089)
  4. CSS3 Flexbox Container (40)
  5. Qwop (40212)

Popular pages this month

  1. Qwop (7387)
  2. Drag Racer V3 (5115)
  3. Bubbles3 (2030)
  4. List with All the Games (1718)
  5. Flash Games - Free online Games (1605)