I set a session variable on login subdomain, and response json from another subdomain if the login was successful, the responsed json is checked by a script and the script does a location.href = "new url"
. On the redirected site "new url" I want to check my session variables if the user is logged in or not, but there are no session variables set. Does location.href = ""
destroy my session? How to fix this problem? session.cookie_domain
is set to '.mydomain.com'
.
login.mydomain.com:
$.post('http://api.mydomain.com/index.php', {action: 'login', username: username, password: password}, function(response) {
var success = $.parseJSON(response);
if(success.success == 'true') {
location.replace = 'http://my.mydomain.com';
}
});
api.mydomain.com:
session_start();
$_SESSION['active'] = true;
header('Access-Control-Allow-Origin: http://login.mydomain.com');
echo '{"success": "true"}';
my.mydomain.com:
session_start();
if(!isset($_SESSION['active']) && !$_SESSION['active']) {
header("Location: http://login.mydomain.com");
echo $_SESSION['access_token'].' test';
}
else {
echo 'Success!';
}