About system variables and environment variables in php
This article introduces the relevant knowledge about system variables and environment variables in PHP. Friends in need can refer to it.
In daily PHP programming, you sometimes encounter modifications to system variables and environment variables to adapt to simple and efficient PHP development. In a virtual host environment, sometimes it is necessary to set the PHP environment variable value through the PHP environment variable operation function. This article introduces how to set the PHP environment variable $_SERVER and PHP system constants for your reference. PHP provides many default system variables for obtaining system configuration information, network request-related information, etc. The default system variables and their functions are as follows: Variable function $GLOBALS[] stores all global variables in the current script, where KEY is the variable name and VALUE is the variable value. $_SERVER[] Current WEB server variable array $_GET[] stores the data in the form submitted with the GET method $_POST[] stores the data in the form submitted using the POST method $_COOKIE[] Gets or sets the variable array stored in the user's browser cookies $_FILES[] stores the data submitted by uploaded files to the current script $_ENV[] stores the current WEB environment variables $_REQUEST[] stores an array of all requests in the submitted form, including everything in $_GET, $_POST, $_COOKIE, and $_SESSION $_SESSION[] stores the session variable array of the current scriptDue to different location files, the content displayed in different environments may be different. Like system variables, PHP also provides some default system constants for use. These system constants can be applied at any time in the program, but we cannot change the values of these constants arbitrarily. Some default system constants commonly used in PHP and their functions are shown in Table 2-2 Show. Constant function __FILE__ stores the absolute path and file name of the current script __LINE__ stores the line number where the constant is located __FUNCTION__ The name of the function where the constant is stored __CLASS__ is the name of the class in which the constant is stored. PHP_VERSION stores the current PHP version number PHP_OS stores the operating system of the current server$_GET and $_POST are mainly for data submitted by FORM forms, $_COOKIE and $_SESSION are mainly for client browser and server-side session data. $_FILES is mainly for the data submitted when uploading files, $_REQUEST is mainly for the submission form All request arrays in the list, including all contents in $_GET, $_POST, and $_COOKIE, you can use the print_r function to output $_REQUEST or $_COOKIE respectively for comparison. Introduction to PHP environment variable $_SERVER It is a PHP global environment variable that contains server-side related information. $HTTP_SERVER_VARS is used in versions before PHP4.1.0. $_SERVER['PHP_SELF'] The file name of the currently executing script, related to the document root. In the FORM form, if the executable file is itself, you can use $_SERVER['PHP_SELF'] in ACTION. The advantage is that when the executable file name You don't need to frequently replace the file name in ACTION when there are changes.
$_SERVER['SERVER_NAME'] The name of the server host where the currently running PHP program is located. $_SERVER['REQUEST_METHOD'] The request method when accessing the page, namely GET, HEAD, POST, PUT. $_SERVER['DOCUMENT_ROOT'] The document root directory where the currently running PHP program is located. That is the definition in the PHP.INI file. $_SERVER['HTTP_REFERER'] links to the URL address of the previous page of the current page. Very useful in page jump function. $_SERVER['REMOTE_ADDR'] The IP address of the visitor who is browsing the current page. $_SERVER['REMOTE_HOST'] The host name of the user who is browsing the current page. $_SERVER['REMOTE_PORT'] The port used by the browsing user to connect to the server. $_SERVER['SCRIPT_FILENAME'] The absolute path name of the currently executing script. $_SERVER['SERVER_PORT'] The port used by the server $_SERVER['SCRIPT_NAME'] contains the path of the current script. This is useful when the page needs to point to itself. $_SERVER['REQUEST_URI'] The URI required to access this page. Such as "/index.html". $_SERVER['PHP_AUTH_USER'] is used in the HTTP user login authentication function. This variable is the user name entered by the user. $_SERVER['PHP_AUTH_PW'] is used in the HTTP user login authentication function. This variable is the password entered by the user. $_SERVER['AUTH_TYPE'] is used in the HTTP user login authentication function. This variable is the authentication type. Note: The above-mentioned PHP global environment variables, when register_globals in php.ini is set to on, these variables are available in all PHP program scripts, that is, the $_SERVER array is separated. Of course, for safety reasons, It is better not to turn register_globals on. PHP system constants __FILE__ The absolute path and file name of the current PHP program script __LINE__ stores the line number where the constant is located __FUNCTION__ stores the function name where the constant is located __CLASS__ The name of the class in which the constant is stored PHP_VERSION stores the current PHP version number, which can also be obtained through the PHPVERSION() function. PHP_OS stores the operating system of the current serverFor more information about the PHP environment variable $_SERVER, please refer to the PHP manual. In addition, in a virtual host environment, the PHP environment variable value needs to be set through the PHP environment variable operation function. Ini_set and ini_get are mainly used. There are more such functions, such as error report settings in PHP, etc., which are actually involved. For relevant content in PHP.INI, you can find some documents for reference. |

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...
