php允许多个域名跨域问题

php开发中跨域报错问题

The value of the ‘Access-Control-Allow-Credentials’ header in the response is ‘’ which must be ‘true’ when the request’s credentials mode is ‘include’. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute

以上问题出现在ajax跨域访问问题
出现以上问题首先设置允许跨域的域名
在入口文件中加上以下代码

//以百度为例
header('Access-Control-Allow-Origin:http://www.baidu.com');
//必须设置是否携带cookie相关参数 解决才能解决此问题
//允许携带证书式访问(携带cookie)
**header('Access-Control-Allow-Credentials:true');**

php允许多个域名跨域解决方案

// [ 应用入口文件 ]
$allow_origin = array(
	//你的访问域名
    'https://s.xxx.com',
);
$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';
if(in_array($origin, $allow_origin)){
    header('Access-Control-Allow-Origin:'.$origin);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值