服务器端 跨域设置 PHP

服务器端 跨域设置 PHP

  $allowHosts = ['http://www.xxx.xxx'];

   $requestHost = $req->server('HTTP_ORIGIN','');//获得请求头的域名信息

   if(in_array($requestHost,$allowHosts)){

       header("Access-Control-Allow-Origin:".$requestHost);

       header("Access-Control-Allow-Headers:X-Requested-With,Content-Type");

       header("Access-Control-Allow-Methods:post");

       header("Access-Control-Allow-Credentials:true");
   }

你可能感兴趣的:(php,服务器,php,服务器,跨域)