Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-02-2012, 04:52 AM   PM User | #1
huyhoang08
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
huyhoang08 is an unknown quantity at this point
Session lost when make ajax cross sub domain

i have 2 sub domain:<br>
http://abc.vn/s.php<br>
http://t1.abc.vn -> point to /1.php
<p>php script bellow:</p>
**s.php**
<?php
//make session avaiable on all subdomain
session_name('hoang'); //set session name
session_set_cookie_params(0, '/', '.abc.vn');
@session_start();


$_SESSION['a']='A';
?>
<script>

function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
//xhr.withCredentials = "true";
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var request = createCORSRequest("get", "http://t1.abc.vn");
if (request){
//request.setRequestHeader('Origin','*');
request.onload = function(){
alert(request.responseText);
};
request.send();
}
</script>

And:
**1.php**
<?php
//make session avaiable on all subdomain
session_name('hoang'); //set session name
session_set_cookie_params(0, '/', '.abc.vn');
@session_start();

if(isset($_SERVER['HTTP_ORIGIN']))
{
$http_origin = $_SERVER['HTTP_ORIGIN']; //check cros
if (in_array($http_origin,array("(URL address blocked: See forum rules)",'(URL address blocked: See forum rules)://localhost')) )
{
header('Access-Control-Allow-Origin: *');
}
}
print_r($_SESSION);
?>

But when ajax call, i get result Array() in 1.php script.
I try to copy ajax url into browser, but it show me right result.
How? i don't understand. Help me.
I will Thanks for all question.
huyhoang08 is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, cross, session, subdomain

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:48 AM.


Advertisement
Log in to turn off these ads.