跨域請求後端配置

php_yt發表於2021-08-14
$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';

$allowOrigin = [
    'https://xx.com',
    'https://xx2.com',
    'http://xx.com',
];

if (in_array($origin, $allowOrigin)) {
    header("Access-Control-Allow-Origin:".$origin);
}

header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');

header('Content-type: text/json; charset=utf-8');

header('Access-Control-Allow-Methods: POST,GET');
本作品採用《CC 協議》,轉載必須註明作者和本文連結
focus

相關文章