PHP system variables Environment Variables

Source: Internet
Author: User
Tags server array

In PHP website development, you often need to set and apply the PHP environment variables to meet the needs of the website. In the virtual host environment, sometimes we need to use the PHP environment variable operation letter.
To set the PHP environment variable value. For this reason, we need to be familiar with PHP environment variables first. Today I will share with you some details about the PHP environment variables $ _ server and PHP system constants.
Description.

PHP provides many default system variables for obtaining system configuration information and network request information. The default system variables and their functions are shown in Table 2-1.

Variable

Function

$ Globals []

Stores all global variables in the current script. The key is the variable name, and the value is the variable value.

$ _ Server []

Current Web server variable array

$ _ Get []

Store the data in the form submitted using the get Method

$ _ Post []

Store the data in the form submitted using the POST method

$ _ Cookie []

Obtains or sets the array of variables stored in cookies in the user's browser.

$ _ FILES []

Store the data uploaded to the current script

$ _ Env []

Store Current Web Environment Variables

$ _ Request []

Store all request arrays in the submission form, including
$ _ Get, $ _ post, $ _ cookie, and all content in $ _ Session

$ _ Session []

Array of session variables for storing the current script

Different files are displayed in different environments.

Like system variables, PHP also provides some default system constants for use. These System constants can be applied in programs at any time, but we cannot arbitrarily change the values of these constants. Some common default system constants in PHP and their functions are shown in Table 2-2.

Constant

Function

_ File __

Store the absolute path and file name of the current script

_ Line __

The row number that stores the constant.

_ Function __

Name of the function that stores the constant

_ Class __

Name of the class where the constant is stored

Php_version

Store the current PHP version number

Php_ OS

Operating system for storing the current server

$ _ Get
And $ _ post are mainly for the data submitted by form forms, and $ _ cookie and $ _ Session are mainly for the client browser and server session data. $ _ FILES mainly targets the data submitted during file upload. $ _ Request mainly targets all request arrays in the submission form, including all content in $ _ Get, $ _ post, and $ _ cookie, you can use the print_r function to output $ _ request or $ _ cookie for comparison.

PHP environment variable $ _ server Introduction

Is a global PHP environment variable that contains server-side information. $ http_server_vars is used in versions earlier than php4.1.0.

  $ _ Server ['php _ Self ']The file name of the script being executed, which is related to document root. In form, if the execution file is itself, you can use $ _ server ['php _ Self '] in action, the advantage is that when the execution file name changes, you can not frequently Replace the file name in the action.

  $ _ Server ['server _ name']Name of the server host of the currently running PHP program.

  $ _ Server ['request _ method']The request method used to access the page, namely get, Head, post, and put.

  $ _ Server ['document _ root']The document root directory of the currently running PHP program. That is, the definition in the PHP. ini file.

  $ _ Server ['HTTP _ referer']The URL of the previous page that is linked to the current page. This function is useful in page navigation.

  $ _ Server ['remote _ ADDR ']Browsing the IP address of the visitor on the current page.

  $ _ Server ['remote _ host']The host name of the user browsing the current page.

  $ _ Server ['remote _ port']The port used by the user who is visiting to connect to the server.

  $ _ Server ['script _ filename']The absolute path name of the currently executed script.

  $ _ Server ['server _ port']Port used by the server

  $ _ Server ['script _ name']The path that contains the current script. This is useful when the page needs to point to itself.

  $ _ Server ['request _ URI ']The URI required to access this page. For example, "/index.html ".

  $ _ Server ['php _ auth_user ']In the HTTP user logon authentication function, this variable is the user name entered by the user.

  $ _ Server ['php _ auth_pw ']In the HTTP user logon authentication function, this variable is the password entered by the user.

  $ _ Server ['auth _ type']In the HTTP user logon authentication function, this variable is the authentication type.

  Note: The Global Environment Variables of PHP mentioned above are in PHP. when register_globals in INI is set to on, these variables are available in all PHP scripts, that is, the $ _ server array is separated. Of course, it is better not to open register_globals for security considerations.

PHP system constant

  _ File __The absolute path and file name of the current PHP script

  _ Line __The row number that stores the constant.

  _ Function __Name of the function that stores the constant

  _ Class __Name of the class where the constant is stored

  Php_versionStore the current PHP version number, which can also be obtained through the phpversion () function.

  Php_ OSOperating system for storing the current server

For more information about the PHP environment variable $ _ server, see the PHP help manual, the article mentioned at the beginning that in the virtual host environment, we need to use the PHP environment variable operation function to set the PHP environment variable value, mainly using ini_set and ini_get. In fact, there are more such functions, for example, the error report settings in PHP involve PHP. ini.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.