php设置多域名跨域

header('Access-Control-Allow-Credentials: true');
        //多域名跨域
        $allow_origin = array(
            'http://localhost:8080',
            'http://localhost:8081',
        );
        $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';  //跨域访问的时候才会存在此字段
        if (in_array($origin, $allow_origin)) {
            header('Access-Control-Allow-Origin:' . $origin);
        } else {
            return;
        }
        header('Access-Control-Allow-Headers: Authorization, 
        Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X- 
        Requested-With');
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
        header('Access-Control-Max-Age: 1728000');
        if(request()->isOptions()){
            exit();
        }

你可能感兴趣的:(php设置多域名跨域)