Home > Article > Backend Development > PHP cross-domain header function (code example)
The previous article recorded PHP’s cross-domain solution: JSONP; https://www.php.cn/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!