PHP Global Variables-Super global variables

Source: Internet
Author: User

PHP Global Variables-Super global variables

Many of the predefined variables in PHP are "hyper-global", which means they are available in all scopes of a script. There is no need to perform a global $variable in a function or method; You can access them.

These hyper-global variables are:

    • $GLOBALS
    • $_server
    • $_request
    • $_post
    • $_get
    • $_files
    • $_env
    • $_cookie
    • $_session
$GLOBALS-Referencing all variables available in the global scope

$GLOBALS This global variable is used anywhere in the PHP script to access global variables (from functions or methods).

PHP stores all global variables in an array named $GLOBALS [index]. The name of the variable is the key of the array.

The following example shows how to use the Super global variable $GLOBALS:

<?php $x = 75; $y = 25; function addition () {   $GLOBALS [' z '] = $GLOBALS [' x '] + $GLOBALS [' Y ']; addition (); Echo $z;?>

In the above example, because Z is a variable in the $GLOBALS array, it can also be accessed outside of the function.

PHP $_server

$_server This hyper-global variable holds information about the header, path, and location of the script.

The following example shows how to use some of the elements in $_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 ');? >
/lianxi/mysql.php
Www.1223.com
Www.1223.com
http://www.1223.com/lianxi/
mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/54.0.2840.99 safari/537.36
/lianxi/mysql.php
127.0.0.1

PHP Global Variables-Super global variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.