求助hprose的session、cookie跨域

浏览:1426 发布日期:2015/04/08 分类:求助交流 关键字: thinkphp tp hprose session cookie 跨域问题
项目需要开发一套共用数据资源的系统,实现多个域名,a.xxx.com,b.xxx.com,
a.ooo.com,b.ooo.com等很多个域名需要实现同步登录。
我想出的解决方案是,用 Hprose,在测试的时候发现,并不能实现SESSION跨域,已经查过很多前辈分享的经验了。
服务器代码:<?php
namespace Main\Controller;
use Think\Controller\HproseController;
class ServerController extends HproseController{
    protected $crossDomain = true;
    protected $P3P = true;
    protected $get = true;
    protected $debug = true;
    public function test1(){
        return  cookie('user');
    }
    public function test2(){
        
       cookie('user','yize',900);
        
    }
}
客户端代码:<?php
namespace Main\Controller;
use Think\Controller;
class HproseController extends Controller {
    public function indexAction(){
        vendor('Hprose.HproseHttpClient');
        $client = new \HproseHttpClient('http://www.servername.com/server');
        $client->keepSession();  //用了这个,至少同一个子域名设置session、cookie可以获得,当然,关了浏览器,再打开,cookie表示已经消失
        // 或者采用
        //$client = new \HproseHttpClient();    //用这个直接报错
        // $client->useService('http://www.servername.com/server');
        $result = $client->test1();    //
        print_r( $result);
    }
    
    public function setAction(){
        vendor('Hprose.HproseHttpClient');
        $client = new \HproseHttpClient('http://www.servername.com/server');
        $client->keepSession();  //这个用HproseHttpClient:keepSession()会报错,明明是静态方法!!!
        // 或者采用
        //$client = new \HproseHttpClient();
        //$client->useService('http://www.servername.com/server');
        $result = $client->test2();
        echo $result;
    }
}
希望有这方面经验的朋友,分享一下心得呗,拜谢!
最佳答案
评论( 相关
后面还有条评论,点击查看>>