Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How PHP uses built-in variables that are always available in all scopes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how PHP uses the built-in variables that are always available in all scopes. It is very detailed and has some reference value. If you are interested, you must finish reading it.

PHP hyperglobal variable

Hyperglobal variables, introduced in PHP 4.1.0, are built-in variables that are always available in all scopes.

Many of the predefined variables in PHP are "super-global" and are available in all scopes of a script.

These hyperglobal variables can be accessed without executing "global $variable;" in a function or method.

$GLOBALS$_SERVER$_REQUEST$_POST$_GET$_FILES$_ENV$_COOKIE$_SESSION

$GLOBALS-references all available variables in the global scope

GLOBALS is used to access global variables anywhere in the PHP script (either from a function or method).

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

Note: in the above example, since z is a variable in the $GLOBALS array, it can be accessed outside of the function.

PHP $_ SERVER

A hyperglobal variable like $_ SERVER holds information about the header, path, and script location.

Note: some elements of $_ SERVER are used in this example. The important elements that can be accessed in $_ SERVER are as follows:

$_ SERVER ["PHP_SELF"] / / returns the file name of the currently executing script $_ SERVER ["GATEWAY_INTERFACE"] / / returns the version of the CGI specification used by the server $_ SERVER ["SERVER_ADDR"] / / returns the IP address of the server where the script is running $_ SERVER ["SERVER_NAME"] / / returns the hostname of the server on which the script is currently running SERVER ["SERVER_SOFTWARE"] / / returns the server identification string $_ SERVER ["SERVER_PROTOCOL"] / / returns the name and version of the communication protocol when the request page is requested $_ SERVER ["REQUEST_METHOD"] / / returns the request method used to access the page $_ SERVER ["REQUEST_TIME"] / / returns the timestamp $_ SERVER ["QUERY_STRING"] / / returns the query string If you access this page $_ SERVER ["HTTP_ACCEPT"] / / return the request header $_ SERVER ["HTTP_ACCEPT_CHARSET"] / / return the Accept_Charset header $_ SERVER ["HTTP_HOST"] / / return the Host header $_ SERVER ["HTTP_REFERER"] / / return the full URL of the current page ( Unreliable) $_ SERVER ["HTTPS"] / / whether to use the secure HTTP protocol query script $_ SERVER ["REMOTE_ADDR"] / / to return the IP address of the user browsing the current page $_ SERVER ["REMOTE_HOST"] / / return the hostname of the user browsing the current page $_ SERVER ["REMOTE_PORT"] / / return the reason for connecting to the Web server on the user's machine The port number $_ SERVER ["SCRIPT_FILENAME"] / / returns the absolute path to the currently executed script $_ SERVER ["SERVER_ADMIN"] / / indicates the SERVER_ADMIN parameter $_ SERVER ["SERVER_PORT"] / / the port used by the Web server in the Apache server configuration file The default value is 80 $_ SERVER ["SERVER_SIGNATURE"] / / returns the server version and virtual hostname $_ SERVER ["PATH_TRANSLATED"] / / the basic path of the file system where the current script resides (not the document root directory) $_ SERVER ["SCRIPT_NAME"] / / returns the path of the current script $_ SERVER ["SCRIPT_URI"] / / returns the URI of the current page

PHP $_ REQUEST

PHP $_ REQUEST is used to collect data submitted by the HTML form.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report