Home > Backend Development > PHP Tutorial > Solve PHP cross-domain problems by setting response headers through the header function

Solve PHP cross-domain problems by setting response headers through the header function

王林
Release: 2023-04-08 07:54:02
forward
3611 people have browsed it

Solve PHP cross-domain problems by setting response headers through the header function

Set the domain names that are allowed to be accessed:

1. Allow access to all domain names

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

2. Allow access to specified domain names

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

Online learning video tutorial sharing: php video tutorial

Set the request method to allow access:

1. 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

and then set other parameters as needed.

Recommended related articles and tutorials: php tutorial

The above is the detailed content of Solve PHP cross-domain problems by setting response headers through the header function. For more information, please follow other related articles on the PHP Chinese website!

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