Superglobals are specially
defined array variables in PHP that make it easy for you to get information
about a request or its context. They are called superglobal because they are
always accessible, regardless of the scope-that is you can access them from any
function, class or file without having to do anything special .These variable
are : $GLOBALS, $_SERVER, $_REQUEST,
$_POST, $_GET, $_FILE, $_SESSION.
$_SERVER : $_SERVER is used for store information about user
server and current script. We can store IP Address from every site visitor and
we can get useful information about site visitor. $_SERVER is special use for
site referral visitor information. We can use this Global Array store many
information about site visitor in website .Some of more useful $_SERVER values
are :
- $_SERVER [“PHP_SELF”]- the name of the currently running PHP script.
- $_SERVER [“REQUEST_METHOD”]- Which HTTP method was used to request the page (GET, POST).
- $_SERVER [“REQUEST_TIME”] – The time the page request was received, represent as an integer know as a unix timestamp
- $_SERVER [“HTTP_REFERER”] – The address of the previously visited page, if available
$_SERVER [HTTP_HOST]- This
code is used for store information about Host name which is your PHP site
script is loaded. We can use this code for welcome note for visitor to your
site .
Example
<?php
echo “welcome to $_SERVER
[HTTP_HOST] “;
?>
Output- Welcome to local host
Complete Program of $_SERVER
<?php
echo $_SERVER [‘PHP_SELF’];
echo “<br>”;
echo $_SERVER
[‘SERVER_NAME’];
echo “<br>”;
echo $_SERVER [‘HTTP_HOST’];
echo “<br>”;
echo $_SERVER
[‘HTTP_REFERER’];
echo “<br>”;
echo $_SERVER
[‘SCRIPT_NAME’];
echo “<br>”;
?>
Here Video Tutorial