PHP environment variables $ _ SERVER and system constants

Source: Internet
Author: User
Tags server array
$ _ SERVER usage, PHP global variables, PHP environment variables, and PHP System Constants

In PHP website development, PHP is sometimes used to obtain server information. to meet the website's needs, you often need to set and apply the PHP environment variables. in the virtual host environment, sometimes we need to use the PHP environment variable operation function to set the PHP environment variable value. For this reason, we need to be familiar with PHP environment variables first. Today, we will share with you a detailed description of the PHP environment variables $ _ SERVER and PHP System constants.
PHP environment variables include $ GLOBALS [], $ _ SERVER [], $ _ GET [], $ _ POST [], $ _ COOKIE [], $ _ FILES [], $ _ ENV [], $ _ REQUEST [], and $ _ SESSION []. $ _ GET and $ _ POST are mainly for data submitted by FORM forms. $ _ COOKIE and $ _ SESSION are mainly for 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

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 '] 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 where the currently running PHP program is located.

$ _ SERVER ['request _ method'] indicates the request method used to access the page, that is, GET, HEAD, POST, and PUT.

$ _ SERVER ['document _ root'] ROOT directory of the DOCUMENT where the currently running PHP program is located. That is, the definition in the PHP. ini file.

$ _ SERVER ['http _ referer'] link to the URL of the previous page of the current page. This function is useful in page navigation.

$ _ SERVER ['remote _ ADDR '] is browsing the IP address of the visitor on the current page.

$ _ SERVER ['remote _ host'] is browsing the HOST name of the user on the current page.

$ _ SERVER ['remote _ port'] PORT used by the user who is visiting to connect to the SERVER.

$ _ SERVER ['script _ filename'] indicates the absolute path name of the currently executed SCRIPT.

$ _ SERVER ['server _ port'] 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 '] URI required to access this page. For example, "/index.html ".

$ _ SERVER ['php _ AUTH_USER '] is used in the HTTP user logon authentication function. this variable is the user name entered by the user.

$ _ SERVER ['php _ AUTH_PW '] is used in the HTTP user logon authentication function. this variable is the password entered by the user.

$ _ SERVER ['auth _ type'] is used in the HTTP user logon authentication function. this variable is the authentication TYPE.

Note: these global PHP environment variables mentioned above are available 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 _ absolute path and FILE name of the current PHP script

_ LINE _ stores the row number of the constant

_ FUNCTION _ name of the FUNCTION where the constant is stored

_ CLASS _ stores the name of the CLASS where the constant is located.

PHP_VERSION stores the current PHP version, which can also be obtained through the PHPVERSION () function.

PHP_ OS stores the operating system of 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.