Due to the influence of many template codes, we thought php had such a custom variable: $ _ SERVER ['HTTP _ X_REQUESTED_WITH ']. In fact, this is not the case at all.
$ _ SERVER is an array containing header information, path, and script locations.
Some header information exists in the system and cannot be changed, such as HOST and USER_AGENT. Note that we often use $ _ SERVER ['HTTP _ host'], $ _ SERVER ['HTTP _ USER_AGENT '], which has an HTTP prefix. In this case, there is no HTTP prefix in the header information, and the information name is only HOST or the like, $ _ SERVER automatically adds an HTTP prefix to them. 1 is to prevent conflicts with other information, and 2 is to indicate that they are header information. therefore, all the variables in $ _ SERVER with an HTTP prefix are header information, but none are available, for example, $ _ SERVER ['query _ string']. $ _ SERVER ['php _ SELF '] and so on.
You can create custom header information and send the information to the SERVER. The SERVER records the header information and stores them in the $ _ SERVER variable, of course, the variable name is changed to "HTTP _" connected to the user's variable name. for example, the above ajax request is judged. in fact, before sending an asynchronous request to the server, add a header to the header. The actual statement should be:
HttpRequest object. setRequestHeader ("X_REQUESTED_WITH", "arbitrary string"); whether the SERVER exists through $ _ SERVER ['HTTP _ X_REQUESTED_WITH, or a specific value to determine whether it is an ajax request or which ajax request is required. therefore, this not only verifies whether the request is an ajax request, but also obtains more information.
We can also set any other information in the header for data exchange with the server.
For example, xmlHttpRequest. setRequestHeader ("test", "just a test"); then the value of the variable $ _ SERVER ['HTTP _ test'] on the requested SERVER Page is "just a TEST "; note that the test in front of it is not case sensitive. $ _ SERVER ['HTTP _ test'] must be capitalized.