PHP Global Variables - Superglobal Variables
Superglobal variables were introduced in PHP 4.1.0 and are built-in variables that are always available in all scopes.
PHP Global Variables - Superglobal Variables
Many of the predefined variables in PHP are "superglobal", which means they Available in all scopes of a script. They can be accessed within a function or method without executing global
$variablename;.
PHP super global variable list:
# #·$GLOBALS
##· $_SERVER
· $_REQUEST
· $_POST
##· $_GET· $_FILES
##· $_ENV
· $_COOKIE
##· $_SESSION
this In this chapter we will explain several commonly used super global variables, and we will introduce the remaining variables in the next few chapters
##PHP $GLOBALS
$GLOBALS is a super global variable group of PHP that can be accessed in the entire scope of a PHP script.
$GLOBALS is a global combined array containing all variables. The name of the variable is the key of the array.
Example
The following example introduces how to use the super global variable $GLOBALS:
Program running result:
100
In the above example z is a $ Super global variable in the GLOBALS array, which can also be accessed outside the function.
PHP $_SERVER
$_SERVER is a server that contains information such as header, path, and script location. locations) and other information. The items in this array are created by the web server. There is no guarantee that every server will offer all items; servers may ignore some, or serve items not listed here.
Examples
The following examples show how to use elements in $_SERVER:
"; echo $_SERVER['SERVER_NAME']; echo "
"; echo $_SERVER['HTTP_HOST']; echo "
"; echo $_SERVER['HTTP_REFERER']; echo "
"; echo $_SERVER['HTTP_USER_AGENT']; echo "
"; echo $_SERVER['SCRIPT_NAME']; ?>Program running results:
## Element/Code/Basis/superglobals/superglobals_1.php
localhost
localhost
http://localhost/Basis/superglobals/
Mozilla/5.0 (Windows NT 6.1 ; Win64; Important elements and explanations$_SERVER['SERVER_NAME']
$_SERVER['PHP_SELF'] The IP address of the server where the script is currently running.The file name of the currently executing script is related to the document root. For example, using $_SERVER['PHP_SELF'] in a script at http://example.com/test.php/foo.bar will result in /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. containing) file. Starting with PHP version 4.3.0, this variable will contain the script name if PHP is running in command line mode. This variable is not available in previous versions.
$_SERVER['GATEWAY_INTERFACE']
The version of the CGI specification used by the server; for example, "CGI/1.1".
$_SERVER['SERVER_ADDR']
The host name of the server where the script is currently running. If the script is running on a virtual host, the name is determined by the value set for that virtual host. (eg: m.sbmmt.com)
##$_SERVER['SERVER_SOFTWARE'] Server identification string , given in the header information when responding to the request. (For example: Apache/2.2.24) $_SERVER['SERVER_PROTOCOL'] The name and version of the communication protocol when requesting the page. For example, "HTTP/1.0". $_SERVER['REQUEST_METHOD'] The request method used to access the page; for example, "GET", "HEAD", "POST", "PUT". $_SERVER['QUERY_STRING'] The timestamp when the request started. Available since PHP 5.1.0. (For example: 1377687496)
##$_SERVER['REQUEST_TIME']query string (query string), if any, page access is performed through it.
$_SERVER['HTTP_ACCEPT'] The content of the Accept: item in the current request header, if it exists. $_SERVER['HTTP_ACCEPT_CHARSET'] The content of the Accept-Charset: item in the current request header, if it exists. For example: "iso-8859-1,*,utf-8". $_SERVER['HTTP_HOST'] The content of the Host: item in the current request header, if it exists. Direct the user agent to the address of the page preceding the current page (if one exists). Determined by user agent settings. Not all user agents will set this item, and some also provide the function of modifying HTTP_REFERER. In short, the value is not trustworthy. )
#$_SERVER['HTTP_REFERER'
$_SERVER['HTTPS'] If the script is accessed through the HTTPS protocol, it is set to a non-empty value
$_SERVER['REMOTE_ADDR'] The IP address of the user browsing the current page.
$_SERVER['REMOTE_HOST']
The host name of the user browsing the current page. DNS reverse resolution does not depend on the user's REMOTE_ADDR. $_SERVER['REMOTE_PORT'] The port number used on the user's machine to connect to the web server. This value specifies the SERVER_ADMIN parameter in the Apache server configuration file. If the script is running on a virtual host, this value is that of that virtual host. (eg: someone@php.cn)
#$_SERVER['SERVER_ADMIN']
The port used by the Web server. The default value is "80". If using SSL secure connection, this value is the HTTP port set by the user.
#$_SERVER['SERVER_PORT']
PHP $_REQUEST
Example
The following example shows an input field (input) and submit button (submit) form. When a user submits form data by clicking the "Submit" button, the form data is sent to the script file specified in the action attribute of the
"; echo $age; ?>Program running results:
Tip: If you want to learn more about $_POST and $_GET, please visit our PHP Forms chapter.
Continuing Learning
- Course Recommendations
- Courseware download
IntermediateFront-end Vue3 actual combat [handwritten vue project]
2857 people are watchingElementaryAPIPOST tutorial [Popularization of technical concepts related to network communication]
1795 people are watchingIntermediateIssue 22_Comprehensive actual combat
5521 people are watchingElementaryIssue 22_PHP Programming
5172 people are watchingElementaryIssue 22_Front-end development
8713 people are watchingIntermediateBig data (MySQL) video tutorial full version
4525 people are watchingElementaryGo language tutorial-full of practical information and no nonsense
2794 people are watchingElementaryGO Language Core Programming Course
2814 people are watchingIntermediateJS advanced and BootStrap learning
2563 people are watchingIntermediateSQL optimization and troubleshooting (MySQL version)
3374 people are watchingIntermediateRedis+MySQL database interview tutorial
2963 people are watchingElementaryDeliver food or learn programming?
5708 people are watchingThe courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
- About us Disclaimer Sitemap
- php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
$_SERVER['SERVER_SIGNATURE'] A string containing the server version and virtual host name. The file system where the current script is located (not the document root directory ) base path. This is the result after the server has been imaged from a virtual to real path. ##$_SERVER['PATH_TRANSLATED']
##PHP $_REQUEST is used to collect data submitted by HTML forms .
contains The path to the current script. This is useful when the page needs to point to itself. The __FILE__ constant contains the full path and file name of the current script (such as an include file).
##$_SERVER['SCRIPT_NAME'] Run the program and seeEnter data in the input box and submit the query"; echo $age; ?>