duanguai2781 2011-12-29 16:51
浏览 62
已采纳

同一会话,不同的域,设置会话ID

I have a couple of domains which i want to shere sessions. I have created a method like this:

The user login is done in a central place and the sessions are saved in the database.

Lets say the user A wants to go to abc.com domain. My app redirects it to the main authentication domain where he logs in. After login is generated an auth token which is saved in a field in the sessions table and it is pass back to the abc.com application.

There I use the auth_token to get the session_id from the database and to set the session_id of abc.com the same.

The problem is that it allways creates a new session.

This is my code of the abc.com

$sessionId = // get from the database using the auth_token.
 /* CLOSE PREVIOUS SESSION */
            session_destroy();

// sets the new id.  
            session_id($sessionId);

            /** start new session * */
            session_start();

What i am missing?. I am using php with Symfony framework. Dont know if it´s related with symfony session handling.

  • 写回答

1条回答 默认 最新

  • douba1617 2011-12-30 11:38
    关注

    Ok. I solved my problem. I had to delete the old session cookie after calling session_destroy().

    Here is my full code if someone is interested:

    $sessionId =  // get session id from  the database using the auth_token
    session_destroy();
    
    $this->getResponse()->setCookie('mycookie',null,time()-3600);
    
    session_id($sessionId);
    
    /** start new session * */
    
    session_start();
    
    $this->getResponse()->setCookie('mycookie', $sessionId,null,null,'mydomain');
    

    Thanks everyone for the help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本