I want to get session data from a subdomain

I am on m.example.com and want to get a session from 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 code:

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

Answer:

Array
(
)
11111111111111111

what are the missing steps

+4
source share
1 answer

Session is not managed for subdomains. You must use a cookie.

-2
source

Source: https://habr.com/ru/post/1533066/


All Articles