Summary of various methods of php predefined variables _ PHP Tutorial

Source: Internet
Author: User
Summary of various methods of php pre-defined variables. PHP provides a large number of predefined variables. Because many variables depend on the version and settings of the running server, and other factors, there is no detailed description document. Some predefined variables PHP provides a large number of predefined variables. Because many variables depend on the version and settings of the running server, and other factors, there is no detailed description document. Some predefined variables do not take effect when PHP is run as a command line. A detailed list of these variables

Custom predefined variables

The code is as follows:

Echo "current operating system information". PHP_ OS ."
";
Echo 'file path and FILE name: '. _ FILE __.'
';
Echo "current PHP version information". PHP_VERSION ."
";
?>

System predefined variables

$ GLOBALS
Contains a reference to a variable that is valid globally for each current script. The key name of the array is the name of the global variable. $ GLOBALS array exists from PHP 3.

$ _ SERVER
Variables are set by the web server or directly associated with the execution environment of the current script. Similar to the old $ HTTP_SERVER_VARS array (still valid, but not used ).

$ _ GET
Variables submitted to the script through URL requests. Similar to the old $ HTTP_GET_VARS array (still valid, but not used ).

$ _ POST
Variables submitted to the script through the http post method. Similar to the old $ HTTP_POST_VARS array (still valid, but not used ).

$ _ COOKIE
Variables submitted to the script through HTTP Cookies. Similar to the old $ HTTP_COOKIE_VARS array (still valid, but not used ).

$ _ FILES
Variables submitted to the script by uploading the http post file. Similar to the old array $ HTTP_POST_FILES array (still valid, but not used ). For more information, see POST Upload.
$ _ ENV
Variables submitted to the script in the execution environment. Similar to the old $ HTTP_ENV_VARS array (still valid, but not used ).

$ _ REQUEST
This array is not trustworthy because the GET, POST, and COOKIE mechanisms are used to submit scripts to variables. All the existence or not of the variables contained in the array and the Order of the variables are defined according to the variables_order configuration instructions in php. ini. This array does not have a corresponding version before PHP 4.1.0. See import_request_variables ().

Since PHP 4.3.0, the file information in $ _ FILES no longer exists in $ _ REQUEST.

Note: when running in command line mode, this array will not contain argv and argc entries; they already exist in the array $ _ SERVER.

$ _ SESSION
The variable currently registered to the script session. Similar to the old $ HTTP_SESSION_VARS array (still valid, but not used ).

$ _ SERVER ['php _ SELF ']

The file name of the script being executed, which is related to document root. For example, using $ _ SERVER ['php _ SELF '] in a script with a URL address of http://example.com/test.php/foo.bar will get the result of/test. PHP/foo. bar. If PHP is run as a command line, the variable is invalid.

$ _ SERVER ['server _ name']

Name of the server host where the script is currently running. If the script runs on a VM, the name is determined by the value set by that VM. For example, if the URL is/test. php $ _ SERVER ['server _ name'], this result is displayed.

Example

The code is as follows:

// User sent a GET header with key = secret_access, val = true, so

Echo $ _ GET ["secret_access"]; // output: true
Echo $ secret_access; // output:

Session_start ();

// In previous logic, you set session variable $ secret_access = false

Echo $ _ SESSION ["secret_access"]; // output: false
Echo $ secret_access; // output: false

Extract_globals (); // Globals put into "normal" variables

Echo $ _ GET ["secret_access"]; // output: true
Echo $ _ SESSION ["secret_access"]; // output: false
Echo $ secret_access; // output: true

// Variables are compromised!
// Do not use $ secret_access!
// USE $ _ SESSION ["secret_access"] instead !!!

?>

The http://www.bkjia.com/PHPjc/628760.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/628760.htmlTechArticlePHP provides a large number of predefined variables. Because many variables depend on the version and settings of the running server, and other factors, there is no detailed description document. Some predefined variables...

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.