![]() |
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. |
| All times are GMT +1. The time now is 07:54 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.