PHP implements cross-origin. PHP implements cross-origin. PHP implements cross-origin. PHP implements cross-origin. Some interfaces of the client software are implemented using HTML, CSS, and Javascript. these files are stored locally on the client, how to implement cross-origin by loading PHP in the form of local files, and implement cross-origin by PHP
Some interfaces of the client software are implemented using HTML + CSS + Javascript. these files are stored locally on the client and loaded as local files. However, in some cases, you need to connect to the server to obtain some information. If no processing is performed, the request fails. the returned information is as follows:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed Access.
This is because the browser's cross-origin policy takes effect and blocks cross-origin requests. You can see the HTTP request process. In the first request to the backend, the browser realized that it was accessing a cross-resource. instead of directly sending a GET request to obtain data, it sent an OPTIONS request asking whether the resource can be accessed. We call it a Preflight request. by default, because the same-Origin policy exists, the Header returned by this request does not have the 'access-Control-Allow-origin' attribute, so the Access fails.
To implement cross-origin, the key lies in the server. the client code can be compiled in a normal way. For the server, you only need to add this attribute to the returned header information when receiving the OPTIONS request. the code is as follows:
header("Access-Control-Allow-Origin: *");
Note that all information must be set before it is output to the client.
The above section describes how PHP implements cross-domain content. I hope it will be helpful to you!
Some interfaces of the client software are implemented using HTML + CSS + Javascript because of work requirements. these files are stored locally on the client and loaded as local files...