Super global variables, a global combined array containing all variables. The name of the variable is the key of the array.
$name="why";//定义变量name,并初始化 function echoName() { //通过全局数组$GLOBALS来引用外部变量 echo "myname is ".$GLOBALS['name']."<br>"; } echoName();
The result is: myname is why.
The role of global is equivalent to passing parameters. If you want to use a variable declared outside the function, use global to declare the variable, which is equivalent to passing Once the variable is passed in, it can be referenced.
$name="why";//声明变量$name,并初始化 function echoName1() { //在函数echoName1()里使用global来声明$name global $name; echo "the first name is ".$name."<br>"; } echoName1();
The result is: the first name is why
$_SERVER is a file containing header information (header), path (path), and script location (script locations) and other information array. 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.
$_SERVER[‘HTTP_HOST’] Request the Host content in the header information to obtain the current domain name.
$_SERVER["SERVER_NAME"] Output the ServerName in the configuration file httpd.conf, which is generally the same as the HTTP_HOST value, but if the server port is not the default port 80, or the protocol specification When it is not HTTP/1.1, HTTP_HOST will contain this information, but SERVER_NAME may not. (Mainly depends on the configuration file settings).
$_SERVER["HTTP_USER_AGENT"] Obtain user-related information, including user browser, operating system and other information.
$_SERVER[‘HTTP_ACCEPT’] ACCEPT header information of the current request.
$_SERVER["HTTP_ACCEPT_LANGUAGE"] This value is sent by the browser and indicates the user's default language setting. The following q value indicates the user's preference for the language.
$_SERVER["HTTP_ACCEPT_ENCODING"] Most modern browsers support gzip compression and will report this information to the server. At this time, the server will send the compressed HTML to the browser. This can reduce file size by nearly 80% to save download time and bandwidth.
$_SERVER["HTTP_COOKIE"] Browser cookie information.
$_SERVER[“HTTP_CONNECTION”] The connection status of the current request.
$_SERVER[“HTTP_UPGRADE_INSECURE_REQUESTS”] indicates that the browser can understand the request sent by the server,
$_SERVER[“HTTP_CACHE_CONTROL”] Indicates whether the browser will cache this page information.
$_SERVER["PATH"] The file system where the current script is located.
$_SERVER["SystemRoot"] The operating system of the current server.
$_SERVER["COMSPEC"] points to the path of cmd.exe.
$_SERVER[“PATHEXT”] Environment variable setting.
$_SERVER["WINDIR"] The system directory pointed to by the script.
$_SERVER["SERVER_SIGNATURE"] A string containing the server version and virtual host name.
$_SERVER[“SERVER_SOFTWARE”] Server software configuration information.
$_SERVER["SERVER_ADDR"] The IP address of the server currently running the script.
$_SERVER[“SERVER_PORT”] Server port.
$_SERVER["REMOTE_ADDR"] User IP browsing the web.
$_SERVER[“DOCUMENT_ROOT”] The root directory where the currently running script is located.
$_SERVER["REQUEST_SCHEME"] Server communication protocol, is http or https.
$_SERVER[“CONTEXT_PREFIX”] prefix.
$_SERVER[“CONTEXT_DOCUMENT_ROOT”] The document root directory where the current script is located.
$_SERVER[“SERVER_ADMIN”] Server administrator information.
$_SERVER["SCRIPT_FILENAME"] The absolute path of the currently executing script.
$_SERVER ["REMOTE_PORT"] The port used by users to connect to the server.
$_SERVER["GATEWAY_INTERFACE"] The version of the CGI specification used by the server.
$_SERVER["SERVER_PROTOCOL"] The name and version of the communication protocol when requesting the page.
$_SERVER[“REQUEST_METHOD”] Requests the way to submit data.
$_SERVER[“QUERY_STRING”] When requested by the server? the following parameters.
$_SERVER["REQUEST_URI"] The current script path, the directory after the root directory.
$_SERVER["SCRIPT_NAME"] The path of the current script. This is useful when the page needs to point to itself.
$_SERVER["PHP_SELF"] The file name of the currently executing script.
$_SERVER["REQUEST_TIME"] Get the timestamp when the request started.
Related recommendations:
php built-in function uses compact()
PHP built-in garbage collection
How to use PHP built-in server
The above is the detailed content of A complete list of PHP built-in methods. For more information, please follow other related articles on the PHP Chinese website!