PHP Task Learning 4: Understanding and Using PHP Super Global Variables_PHP Tutorial

WBOY
Release: 2016-07-21 14:55:02
Original
864 people have browsed it

Understand and use PHP super global variables

Super global variables are also called predefined variables. They are variables that come with the PHP system. They can make your programming more convenient and faster. Its types include:

$GLOBALS
Contains a reference to each variable that is valid in the global scope of the current script. The key names of this array are the names of global variables. The $GLOBALS array exists since PHP 3.
$_SERVER
Variables are set by the web server or directly associated with the execution environment of the current script. Similar to the old array
$_GET
Variables submitted to the script via URL requests.

$_POST
Variables submitted to the script via the HTTP POST method.
$_COOKIE
Variable submitted to the script via the HTTP Cookies method.
$_FILES
Variables submitted to the script via HTTP POST file upload.
$_ENV
Variables submitted by the execution environment to the script.
$_REQUEST
Variables submitted to the script via GET, POST and COOKIE mechanisms.

$_SESSION
The variable currently registered for the script session.

The specific information will not be explained one by one here. You can create a new PHP file and write the following code in the file.

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] phpinfo()
?>

and execute it, you can see the following screen:

In this page, you can view various types of super global variables that exist in the system, and you can also apply them.

The following 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 to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] echo "The current file is ".$_SERVER["PHP_SELF"];
echo "
";
echo "The current server’s IP address is: ".$_SERVER[ "SERVER_ADDR"];
?>

Through the above examples, we found that predefined variables, that is, super global variables, do not need to be defined when used (you can query them through phpinfo), and they start with "$_", and the variable names are all capital letters, with "[ ]" enclose the corresponding parameters.

This is the end of our introduction to constant variables in PHP.

Reprinted from: http://www.cnblogs.com/walkbro/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364488.htmlTechArticleUnderstand and use PHP super global variables Super global variables are also called predefined variables, which are variables that come with the PHP system , which can make your programming more convenient and faster. Its types include...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!