贴代码
public function _initialize(){
???header("Access-Control-Allow-Origin: *");
???header(‘Access-Control-Allow-Headers:x-requested-with,content-type,token,version,shopId,client‘);
???$this->initSession();
}
public function initSession() {
???$rqh = requestHeader();
???$data = getData();
???if($rqh[‘token‘]){
???????//登录状态的初始化
???????session_id($rqh[‘token‘]);
???????session_start();
???}else if($data[‘code_token‘]){
???????//手机验证码初始化
???????session_id($data[‘code_token‘]);
???????session_start();
???}else if(in_array(CONTROLLER_NAME.‘/‘.ACTION_NAME,$this->startSessionByHand)){
???????//登录情况再手动开启session
???}else{
???????session_start();
???}
??
}
// 指定允许其他域名访问
header(‘Access-Control-Allow-Origin:*‘);
// 响应类型
header(‘Access-Control-Allow-Methods:POST‘);
// 响应头设置
header(‘Access-Control-Allow-Headers:x-requested-with,content-type‘);
ajax跨域,设置session
原文地址:https://www.cnblogs.com/Meke/p/9804372.html