Php-mysql Course

$_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:

$_SERVER['INDEX']
- '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:
echo $_SERVER['SERVER_NAME'];
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

<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
?>

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

<?php
// for example, if the URL address of the php script is:  https://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

<?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

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used to add lists into <ul> and <ol> elements?
<dt> <dd> <li>
<ul>
 <li>http://coursesweb.net/html/</li>
 <li>http://coursesweb.net/css/</li>
</ul>
Which value of the "display" property creates a block box for the content and ads a bullet marker?
block list-item inline-block
.some_class {
  display: list-item;
}
Which instruction converts a JavaScript object into a JSON string.
JSON.parse() JSON.stringify eval()
var obj = {
 "courses": ["php", "javascript", "ajax"]
};
var jsonstr = JSON.stringify(obj);
alert(jsonstr);    // {"courses":["php","javascript","ajax"]}
Indicate the PHP class used to work with HTML and XML content in PHP.
stdClass PDO DOMDocument
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>';
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
$elm = $dochtml->getElementById("dv1");
echo $elm->nodeValue;    // CoursesWeb.net
Superglobal $_SERVER Array

Last accessed pages

  1. Read Excel file data in PHP - PhpExcelReader (97351)
  2. Select in MySQL, Output results in HTML Table (19495)
  3. The Mastery of Love (7438)
  4. CSS cursor property - Custom Cursors (6091)
  5. Disable button and Enable it after specified time (17531)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (472)
  2. CSS cursor property - Custom Cursors (79)
  3. The Mastery of Love (70)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (62)
  5. CSS3 2D transforms (46)