Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
Super Global Variables
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. Super Global Variables

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

Super Global Variables

PHP Global Variables - Super globals

global

Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special.

The PHP superglobal variables are:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION

This chapter will explain some of the superglobals, and the rest will be explained in later chapters.

$GLOBALS :

$GLOBALS is a PHP superglobal variable that is used to access global variables from anywhere in the PHP script (also from within functions or methods).

PHP stores all global variables in an array called $GLOBALS["your_index"]. The index holds the name of the variable.

The example below shows how to use the super global variable $GLOBALS:

<?php 
$x = 60; 
$y = 40;
 
function addition() { 
    $GLOBALS["z"] = $GLOBALS["x"] + $GLOBALS["y"]; 
}
 
addition(); 
echo $z; 
?>

Output : 100

$_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["HTTP_USER_AGENT"];
echo "<br>";
echo $_SERVER["SCRIPT_NAME"];
?>

$_SERVER is an array also known as PHP superglobal variable that holds information about headers, paths and script location and entries in these arrays are created by web servers

Code Description
$_SERVER['PHP_SELF'] It is used to display the filename of the currently executing script
$_SERVER['GATEWAY_INTERFACE'] It is used to display the version of the Common Gateway Interface (CGI) the server is using
$_SERVER['SERVER_ADDR'] It is used to display the IP address of the host server
$_SERVER['SERVER_NAME'] It is used to display the host server's name 
$_SERVER['SERVER_SOFTWARE'] It is used to display the server identification string.
$_SERVER['SERVER_PROTOCOL'] It is used to display the name and revision of the information protocol
$_SERVER['REQUEST_METHOD'] It is used to display the request method used to access the page. i.e. 'GET','POST'
$_SERVER['REQUEST_TIME'] It is used to display the timestamp of the start of the request.
$_SERVER['QUERY_STRING'] It is used to display the query string if the page is accessed via a query string
$_SERVER['HTTP_ACCEPT'] It is used to display the Accept header from the current request
$_SERVER['HTTP_ACCEPT_CHARSET'] It is used to display the Accept_Charset header from the current request
$_SERVER['HTTP_HOST'] It is used to display the Host header from the current request
$_SERVER['HTTP_REFERER'] It is used to display the complete URL of the current page (not reliable because not all user-agents support it)
$_SERVER['HTTPS'] Is the script queried through a secure HTTP protocol
$_SERVER['REMOTE_PORT'] It is used to display the port being used on the user's machine to communicate with the web server
$_SERVER['SCRIPT_FILENAME'] It is used to display the absolute pathname of the currently executing script
$_SERVER['SERVER_ADMIN'] It is used to display the value given to the SERVER_ADMIN directive in the web server configuration file.
$_SERVER['REMOTE_ADDR'] It is used to display the IP address from where the user is viewing the current page
$_SERVER['REMOTE_HOST'] It is used to display the Host name from where the user is viewing the current page
$_SERVER['SERVER_PORT'] It is used to display the port which is being used on the local machine to communicate with the web server.
$_SERVER['SERVER_SIGNATURE'] It is used to display the server version and virtual host name which are added to server-generated pages
$_SERVER['PATH_TRANSLATED'] It is used to display the file system based path to the current script
$_SERVER['SCRIPT_NAME'] It is used to display the current script's path
$_SERVER['SCRIPT_URI'] It is used to display the current page's URI

 

$_REQUEST :

  • PHP $_REQUEST is used to collect data after submitting an HTML form.
  • $_REQUEST is used to access the data after submission of HTML Form.
<html>
<body>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // collect value of input field
    $name = $_REQUEST["fname"];
    if (empty($name)) {
        echo "My Name is Php";
    } else {
        echo $name;
    }
}
?>
</body>
</html>

Here is simple example where i have submit form which is point to itself for process with data with GET method. Now in PHP script i am using the super global variable $_REQUEST to get the value of the input field.

$_POST :

PHP $_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.

<html>
<body>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // collect value of input field
    $name = $_POST["fname"];
    if (empty($name)) {
        echo "My Name is Php";
    } else {
        echo $name;
    }
}
?>
</body>
</html>

$_GET :

  • PHP $_GET can also be used to collect form data after submitting an HTML form with method="get".
  • $_GET can also collect data sent in the URL.
<html>
<body>
<?php 
echo "Study " . $_GET["php"] . " at " . $_GET["development"];
?>
</body>
</html>

$_FILES[“FormElementName”] :

It can be used to upload files from a client computer/system to a server.
OR

$_FILES[“FormElementName”][“ArrayIndex”] :

Such as File Name, File Type, File Size, File temporary name.

$_SESSION[“VariableName”] :

A session variable is used to store information about a single user, and are available to all pages within one application.

$_COOKIE[“VariableName”] :

A cookie is used to identify a user. cookie is a small file that the server embedded on user computer.

Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group

Related Topics:
ifference between global variable and super global variable in php php global vs superglobal php superglobals tutorial php $_server examples $_request vs $_get $_request vs $_post how to declare global variable in php php global variable in function

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.