Access-Control-Allow-Origin Multiple Origin Domains?

前端 未结 30 2184
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 07:08

Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header?

I\'m aware of the *, but it is too open. I rea

30条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-21 07:22

    Another solution I'm using in PHP:

    $http_origin = $_SERVER['HTTP_ORIGIN'];
    
    if ($http_origin == "http://www.domain1.com" || $http_origin == "http://www.domain2.com" || $http_origin == "http://www.domain3.com")
    {  
        header("Access-Control-Allow-Origin: $http_origin");
    }
    

提交回复
热议问题