The header function sets the response header to solve the cross domain problem of PHP

Time:2021-10-12

Set the domain name allowed to access:

1. Allow access to all domain names


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

2. Allow access to the specified domain name


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

Set the request mode for 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.

The above is the details of setting the response header through the header function to solve the cross domain problem of PHP. If you have anything to add, you can contact Xiaobian. Thank you for your support for developeppaer.