How PHP implements _php instances across domains

Source: Internet
Author: User

As a result of the work, some client software interface with Html+css+javascript implementation, these files are placed in the client local, as a local file loading, but in some cases, need to connect to the server to obtain some information, if do not do any processing, the request failed, the information returned 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-domain policy works, blocking requests across domains. Look at the HTTP request process and know it. On the first request, the browser realized that it was accessing a cross and resource and did not send a GET request directly to fetch the data, but instead sent a options request asking if the resource could be accessed. We call it the preflight request, which failed because the request returned a header that did not have the ' access-control-allow-origin ' attribute because of the existence of the homologous policy.
If you want to implement Cross-domain, the key is the server, the client's code is written in the normal way. For a server, you only need to add this property to the header information returned in the place where you receive the options request, and the code is as follows:

Header ("Access-control-allow-origin: *");

Note that it must be set before all information is exported to the client.

The above is a small series to introduce you to the PHP how to achieve cross-domain related content, I hope to help you!

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.