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

PHP cross-domain header function (code example)

藏色散人
Release: 2023-04-08 11:26:01
forward
2726 people have browsed it

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:*");
Copy after login

2. Allow specified domain name access

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

Set the request method to allow access:

1. One or more

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

2. All

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

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template