PHP Global Variables

Before going deep into the PHP, a PHP developer or programmer should know about some important PHP Global Variables and their use at the occasion. So in this tutorial I am showing you the important variables and their brief introduction.

Some global variables can be created through the use of define() and others are reserved because of a special function. These variables provide access to different types of data. All global variables listed below are arrays:-


1.   $_SERVER


Browser description from header

[HTTP_USER_AGENT] => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:; Firefox/



The page address that referred the user




The client’s IP address




System root location of current script

[DOCUMENT_ROOT] => /opt/lampp/htdocs



Absolute path of current script

[SCRIPT_FILENAME] => /opt/lampp/htdocs/test.php



The Universal Resource Identifier for the page

[REQUEST_URI] => /test.php?test=value



The current scripts path

[SCRIPT_NAME] => /test.php



The current scripts path

[QUERY_STRING] => test=value



The name of the current script, relative to the root

[PHP_SELF] => /test.php

When submitting a form to the same page/file that contains it, you can use

the $_SERVER[‘PHP_SELF’] variable to dynamically provide the location.

<form method=”POST” action=”<?php  echo $SERVER[‘PHP_SELF’]; ?>”>

<form method=”POST” action=”filename.php”>

 2.   $_REQUEST

Includes all variables provided by $_GET, $_POST, and $_COOKIE

3.  $_POST

Includes all variables submitted through HTTP POST, such as an HTML

form with action=”post”.

 4.   $_GET

Includes all variables submitted through the query string url, either manually or

from a form with action=”get”.

 5.  $_SESSION

Variables assigned to the current session.

 6.  $_COOKIE

Any cookies stored for the current website. Only visible after the page was

reloaded if it was just set using setcookie().

setcookie() – Assigning and deleting cookies

 7.  $_FILES

Variables provided to the script via POST uploads.

 8.  $_ENV

A collection of variables about the server environment.


Contains a reference for all variables, global or otherwise, in the script.

Leave a Reply

Your email address will not be published. Required fields are marked *