PHP Superglobals

Predefined or Superglobals variables are used to provide information from and about the web server, the web browser, and the user.

There are several types of Super Global Variables:-

$_GET – Is used to pass data through URL.  Example:

$_POST – Is used to pass data to server by hiding from URL.

$_REQUEST – Is the combination of $_GET, $_POST, and $_COOKIE.

$_SESSION – is used to maintain session and data from Local machine to Server.

$_COOKIE – Is used to save/get user data on same machine in browser cookies.

$_SERVER – Is an associative array which is used to know server information i.e. IP address, Host name, query string, file name etc.

$_FILES – Is used to handle uploaded files operations in PHP. i.e. file size, type, name etc.


Example – $_SERVER Superglobals                               


echo “Current IP Address is : “.$_SERVER[‘REMOTE_ADDR’];

echo “You are Page at : ” . $_SERVER[‘PHP_SELF’];




Functions in PHP behave similarly to functions in C. When we define the functions, we must specify what values the function can expect to receive.

So let’s create a function. We need to give the function a name and tell it what variables to expect. We also need to define the function before we call it.


function sum($f1, $f2)


$f3 = $f1 + $s2;

return $f3;



echo sum(10,8);


Output: 18

So First, we created our function. Notice how we defined two new variables, called $f1 and $f2. When we call the function, each variable is assigned a value based on the order in which it appears. Then we simply added the two numbers together and returned the result. “Return” here simply means to send the result back.


Enjoy the tutorial? Please spread the word :)

Follow by Email