Global variables
$GLOBALS
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.
globsl
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
$_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!

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.

The session ID should be regenerated regularly at login, before sensitive operations, and every 30 minutes. 1. Regenerate the session ID when logging in to prevent session fixed attacks. 2. Regenerate before sensitive operations to improve safety. 3. Regular regeneration reduces long-term utilization risks, but the user experience needs to be weighed.

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 English version
Recommended: Win version, supports code prompts!