System variables and environment variables in php

Source: Internet
Author: User
Tags server array
System variables and environment variables in php
This article describes how to learn about system variables and environment variables in php.

In daily php programming, system variables and environment variables are sometimes modified to adapt to simple and efficient php development. In the virtual host environment, you sometimes need to use the PHP environment variable operation function to set the PHP environment variable value.

This article describes how to set the PHP environment variables $ _ SERVER and PHP System Constants for your reference.

PHP provides many default system variables for obtaining system configuration information and network request information.

The default system variables and their functions are as follows:

Variable function

$ GLOBALS [] stores all global variables in the current script. The KEY is the variable name, VALUE is the variable VALUE $ _ SERVER [] the current web server variable array $ _ GET [] stores the data in the form submitted using the GET method $ _ POST [] to store the data in the form submitted using the POST method $ _ COOKIE [] get or set the variable array stored in Cookies in the user's browser $ _ FILES [] store the data submitted to the current script by storing the uploaded file $ _ ENV [] store the current WEB environment variable $ _ REQUEST [] stores all REQUEST arrays in the submission form, this includes $ _ GET, $ _ POST, $ _ COOKIE, and $ _ SESSION. $ _ SESSION [] stores the SESSION variable array of the current script.

Different location files may display different content 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 _ stores the absolute path of the current script and the FILE name _ LINE _ stores the row number of the constant _ FUNCTION _ stores the FUNCTION name of the constant _ CLASS _ name of the class where the constant is stored. PHP_VERSION: The current PHP version number. PHP_ OS: 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 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 '] 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 of the current PHP program script and FILE name _ LINE _ store the row number of the constant _ FUNCTION _ store the FUNCTION name of the constant __ CLASS _ stores the name of the CLASS where the constant is located. PHP_VERSION stores the current PHP version number, you can also use 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 Manual. In addition, in the virtual host environment, you need to use the PHP environment variable operation function to set the PHP environment variable value, mainly using ini_set and ini_get, and more such functions, for example, the error report settings in PHP involve PHP. for more information about INI, see references.

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.