$_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 adds a new line into a paragraph?
<b> <br> <p>
First line ...<br>
Other line...
Which CSS property can be used to add space between letters?
text-size word-spacing letter-spacing
#id {
  letter-spacing: 2px;
What JavaScript function can be used to get access to HTML element with a specified ID?
getElementById() getElementsByTagName() createElement()
var elm = document.getElementById("theID");
var content = elm.innerHTML;
Click on the "echo" correct instruction.
echo "CoursesWeb.net" echo "CoursesWeb.net"; echo ""CoursesWeb.net";
echo "Address URL: http://CoursesWeb.net";
Superglobal $_SERVER Array

Last accessed pages

  1. ActionScript 3 - Change MovieClip Color (4800)
  2. Read Excel file data in PHP - PhpExcelReader (33105)
  3. Script Users Register, Login, Online (13590)
  4. Image object (559)
  5. CKEditor Free Image Browse Plugin (4964)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (43804)
  2. PHP-MySQL free course, online tutorials PHP MySQL code (33239)
  3. Read Excel file data in PHP - PhpExcelReader (33105)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (29933)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (27253)