How to implement cross-origin in PHP; how to implement cross-origin in PHP _ PHP Tutorial

Source: Internet
Author: User
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...

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.