www.webdeveloper.com
Results 1 to 1 of 1

Thread: Session lost when make ajax cross sub domain

Threaded View

  1. #1
    Join Date
    Sep 2010
    Posts
    21

    Unhappy 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
    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 answers.
    Last edited by huyhoang08; 11-01-2012 at 11:15 PM. Reason: updated

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles