Php predefined variable _ PHP Tutorial

Source: Internet
Author: User
The predefined variable of php. Predefined variable SERVER variable: _ SERVER note: it is used in php (as the mainstream development language) 4.1.0 and later versions. In earlier versions, HTTP_SERVER_VARS is used. _ SERVER is a predefined variable.
SERVER variable: $ _ SERVER
Note: php 4.1.0 and later versions are used as mainstream development languages. In earlier versions, $ HTTP_SERVER_VARS is used.

$ _ SERVER is an array containing headers, paths, and script locations. The object of the array is created by the web server. It is not guaranteed that all servers can generate all information. the server may ignore some information or generate new information not listed below. This means that a large number of these variables are described in cgi (not many are using it now) 1.1 specification, so you should study it carefully.

This is a "superglobal", or it can be described as an automatic global variable. This only means that it is valid in all scripts. You do not need to use global $ _ SERVER; to access a function or method, just like using $ HTTP_SERVER_VARS.

$ HTTP_SERVER_VARS contains the same information, but it is not an automatic global variable. (Note: $ HTTP_SERVER_VARS and $ _ SERVER are different variables. php (as the mainstream development language) processes them differently .)

If the register_globals command is set, these variables are also available in all scripts; that is, the $ _ SERVER and $ HTTP_SERVER_VARS arrays are separated. For more information, see the security section using Register Globals. These independent global variables are not automatic global variables.

You may find that some $ _ SERVER elements listed below are not available. Note: If you run php (as the mainstream development language) in the command line mode, the elements listed below are hardly valid (or have no practical significance ).



"Php (as the mainstream development language) _ SELF"
The file name of the script being executed, which is related to document root. For example, in the URL address for http://example.com/test.php (as the current mainstream development language)/foo. use $ _ SERVER [php (as the mainstream development language) _ SELF] in bar script to get/test. php (as the mainstream development language)/foo. bar.

If php (as the mainstream development language) is run in the command line mode, the variable is invalid.

"Argv"
Parameters passed to the script. When the script runs in the command line mode, the argv variable is passed to the command line parameters in the C language style of the program. When the GET method is called, the variable contains the requested data.

"Argc"
Contains the number of command line parameters passed to the program (if it is in command line mode ).

"GATEWAY_INTERFACE"
The cgi (not many people are using it now) Standard version used by the server. For example, "cgi (not many people are using it now)/1.1 ".

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.

SERVER_SOFTWARE
The string identified by the server, which is in the header of the response request.

"SERVER_PROTOCOL"
The name and version of the communication protocol on the request page. For example, "HTTP/1.0 ".

"REQUEST_METHOD"
The request method used to access the page. For example, "GET", "HEAD", "POST", and "PUT ".

"QUERY_STRING"
Query string.

"DOCUMENT_ROOT"
The document root directory where the script is currently running. Defined in the server configuration file.

"HTTP_ACCEPT"

Slave SERVER variable: _ SERVER note: it is used in php (as the mainstream development language) 4.1.0 and later versions. In earlier versions, HTTP_SERVER_VARS is used. _ SERVER is...

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.