我想从子域获取会话数据

时间:2014-03-23 15:17:36

标签: php jquery cross-domain

我在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

缺少的步骤是什么?

1 个答案:

答案 0 :(得分:-2)

不管理子域的会话。你必须使用cookie。