yii 跨域问题(访问不用的vue项目)

$allowUrlList=[
    'http://vue.example.cn',
    'http://v.example.com',
];
$url=empty($_SERVER['HTTP_ORIGIN'])?"":$_SERVER['HTTP_ORIGIN'];
if (in_array($url,$allowUrlList)){
    header("Origin:".$url);
    header("Access-Control-Allow-Origin:".$url);
    header("Access-Control-Request-Headers:".$url);
    header("Access-Control-Allow-Credentials:true");
    header("Access-Control-Allow-Headers: Content-Type, X-Requested-With, Cache-Control,Authorization");
    header('Access-Control-Max-Age: 1728000');
    parent::init();
}

猜你喜欢

转载自blog.csdn.net/jjk_2333/article/details/81201156
yii