Understand and use PHP Super global variable _php basics

Source: Internet
Author: User
Tags file upload http cookie http post phpinfo
Recognize and use PHP Super global variables

Super global variables, also known as predefined variables, are the PHP system's own variables, which makes your program more convenient and quick to design. Its types include:

$GLOBALS
Contains a reference to a variable in the global scope that is valid for each current script. The array's key name is the name of the global variable. $GLOBALS array is present starting with PHP 3.
$_server
Variables are set by the Web server or are directly associated with the execution environment of the current script. Similar to old array
$_get
A variable submitted to the script via a URL request.

$_post
A variable that is submitted to the script via the HTTP POST method.
$_cookie
A variable that is submitted to a script via an HTTP cookie method.
$_files
A variable submitted to the script via an HTTP POST file upload.
$_env
Executes the variables that the environment submits to the script.
$_request
Variables submitted to the script via the Get,post and COOKIE mechanisms.

$_session
The variable currently registered to the script session.

The specific information here is not one of the confessed, you can create a new PHP file, in the file to write the following code.

Copy Code code as follows:

<?php
Phpinfo ();
?>

and execute and you can see the following screen

In this page, you can see the various types of super global variables that exist in the system, so you can also apply it.
Here is an example of using a PHP file to display the current file and the IP address of the current server.
The code is as follows:
Copy Code code as follows:

<?php
echo "Current file is". $_server["Php_self"];
echo "<br>";
echo "The current server IP address is:". $_server["Server_addr"];
?>

From the above example, we find that a predefined variable, which is a super global variable, does not need to be defined when it is used (you can query by Phpinfo) and begins with "$_", the variable name is uppercase and the corresponding parameter is enclosed with "[]".

Here, we're done with the constant variables in PHP.
Mago's school is close to the final exam, and the next few days are expected to be less timely. Also hope you forgive me!

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.