Home  >  Article  >  Backend Development  >  PHP cross-domain header function (code example)

PHP cross-domain header function (code example)

藏色散人
藏色散人forward
2020-01-30 19:14:482682browse

PHP cross-domain header function (code example)

The previous article recorded PHP’s cross-domain solution: JSONP; //m.sbmmt.com/js-tutorial-441885.html

In addition to jsonp, it is still possible to set the response header through the header function to solve cross-domain problems:

Set the domain name allowed to be accessed:

1. Allow all Domain name access

header("Access-Control-Allow-Origin:*");

2. Allow specified domain name access

header( 'Access-Control-Allow-Origin:http://a.test.com' );

Set the request method to allow access:

1. One or more

header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');

2. All

header('Access-Control-Allow-Methods:*');

Then set other parameters as needed...

For more php related knowledge, please visit php tutorial!

The above is the detailed content of PHP cross-domain header function (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete