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
Click on the HTML tag which creates an horizontal line in web page.
<br /> <em> <hr />
Some content ...
<hr />
Content under line ...
Which CSS property defines the text color?
font-style font-variant color
h2 {
  color: #cbdafb;
}
Click on the function which searches if a character, or text exists in a string.
indexOf() toString() split()
var str = "Web courses - http://CoursesWeb.net/";
if(str.indexOf("http://") == -1) alert("http:// isn`t in string");
else alert("http:// is in string");
Which function splits a string into an array of strings based on a separator?
array_merge() explode() implode()
$str = "apple,banana,melon,pear";
$arr = explode(",", $str);
var_export($arr);      // array (0=>"apple", 1=>"banana", 2=>"melon", 3=>"pear")
Superglobal $_SERVER Array

Last accessed pages

  1. Zodiac Signs PHP code (7248)
  2. MySQLDumper - Backup MySQL Database (1788)
  3. Upload Files with Express and Multer (1993)
  4. Get Mouse coordinates inside a Div or an Image (16406)
  5. Get Duration of Audio /Video file before Upload (15445)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (310)
  2. CSS cursor property - Custom Cursors (36)
  3. The Mastery of Love (35)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (32)
  5. Read Excel file data in PHP - PhpExcelReader (28)