我在m.example.com上,希望从www.example.com
获取会话php code(session.php):
<?php
ini_set('session.cookie_domain', '.jeelplus.com');
session_set_cookie_params(0, '/', '.jeelplus.com');
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: POST, GET');
header('Access-Control-Allow-Headers: Authorization, X-Requested-With, Content-Type, Origin, Accept');
//header('Access-Control-Allow-Credentials: true');
session_start();
print_r($_SESSION);
echo('11111111111111111');
exit;
?>
jquery代码:
function userIsLoggedIn(){
var logged_in = null;
$.ajaxSetup({cache: false, crossDomain:true, headers: {"X-Requested-With": "XMLHttpRequest"}, xhrFields: { withCredentials: true }})
$.get("http://www.example.com/session.php", {requested: 'foo'}, function (data) {
alert(data);
logged_in = data;
});
}
响应:
Array
(
)
11111111111111111
缺少的步骤是什么?
答案 0 :(得分:-2)
不管理子域的会话。你必须使用cookie。