Specify Multiple Subdomains with Access Control Origin

后端 未结 7 854
爱一瞬间的悲伤
爱一瞬间的悲伤 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:52

    I tried using this approach to achieve constraint on a specific domain basis:

    $allowed_origin = '';
    $parts = explode('.', parse_url($_SERVER['HTTP_HOST'])['host']);
    if(end($parts).".".prev($parts) === "com.domain") {
        $allowed_origin = $_SERVER['HTTP_ORIGIN'];
        header('Acesss-Control-Allow-Origin: '. $allowed_origin);
    }
    

    I hope it works.

    0 讨论(0)
提交回复
热议问题