Access-Control-Allow-Origin 一般情况下只能绑定一个值,当然 * 可以任意,但是不推荐,下面介绍如果绑定多个值。
$origins = ['http://127.0.0.1:7001', 'https://www.cdsy.xyz'];
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
if (in_array($origin, $origins)) {
header("Access-Control-Allow-Origin: " . $origin);
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
}
