Home>Article>Backend Development> 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

王林
王林 forward
2020-01-08 17:51:20 3498browse

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

2. Allow access to specified domain names

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

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');

2, all

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

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!

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