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);
}

本文介绍了在PHP开发中遇到的Ajax跨域请求时,由于'Access-Control-Allow-Credentials'头设置不正确导致的错误。解决方法是在入口文件中设置允许的源并开启携带Cookie的选项。示例代码给出了如何动态设置允许的域名,并允许携带凭证进行跨域访问。

2718

被折叠的 条评论
为什么被折叠?



