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 renders as emphasized text, displaying the text oblique?
<strong> <pre> <em>
<p>Web development courses: <em>CoursesWeb.net</em></p>
Which CSS property defines the space between the element border and its content?
margin padding position
h3 {
  padding: 2px 0.2em;
}
Click on the method which returns the first element that matches a specified group of selectors.
getElementsByName() querySelector() querySelectorAll()
// gets first Div with class="cls", and shows its content
var elm = document.querySelector("div.cls");
alert(elm.innerHTML);
Indicate the PHP variable that contains data from a form sent with method="post".
$_SESSION $_GET $_POST
if(isset($_POST["field"])) {
  echo $_POST["field"];
}
Superglobal $_SERVER Array

Last accessed pages

  1. Get and Modify content of an Iframe (32090)
  2. SHA256 Encrypt hash in JavaScript (31197)
  3. CSS Border (5972)
  4. Register and show online users and visitors (39373)
  5. Simple Ajax-PHP Contact Form Script (1393)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (234)
  2. Read Excel file data in PHP - PhpExcelReader (83)
  3. PHP Unzipper - Extract Zip, Rar Archives (72)
  4. The Four Agreements (69)
  5. The Mastery of Love (59)
Chat
Chat or leave a message for the other users
Full screenInchide