Specify Multiple Subdomains with Access Control Origin

后端 未结 7 852
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-13 17:57

I am trying to allow access to every subdomain on my site in order to allow cross subdomain AJAX calls. Is there a way to specify all subdomains of a site like *.example.c

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-13 18:35

    While the answer works, it does defeat the purpose of the whole thing, since it allows requests from any host.

    I use something like:

    if(isset($_SERVER['HTTP_ORIGIN'])) {
      $origin = $_SERVER['HTTP_ORIGIN'];
      if($origin == 'https://sub1.my-website.com' OR $origin == 'https://sub2.my-website.com') {
        header("Access-Control-Allow-Origin: $origin");
      }
    }
    

提交回复
热议问题