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