Home >Backend Development >PHP Problem >How to set php to allow cross-domain requests

How to set php to allow cross-domain requests

WJ
WJOriginal
2020-06-10 16:36:505616browse

How to set php to allow cross-domain requests

How to set php to allow cross-domain requests?

Add

header(“Access-Control-Allow-Origin: *”);

to the header of the php file. If you want to set up to allow only a certain website to pass, you can set it like this

header(“Access-Control-Allow-Origin: http://test.com”); // 允许test.com发起的跨域请求,其他的都不通过

Related recommendations: php tutorial

The above is the detailed content of How to set php to allow cross-domain requests. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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