同一会话,不同的域,设置会话ID [英] same session, different domains, set session id
问题描述
我有几个域名,我想参加会议。
我创建了一个这样的方法:
用户登录在一个中心位置完成,会话保存在数据库中。
假设用户A想要去abc.com域。我的应用程序将它重定向到他登录的主身份验证域。
登录后生成一个验证令牌,保存在会话表中的字段中,并返回到abc.com应用程序。
在这里,我使用auth_token从数据库获取session_id,并设置abc.com的session_id相同。
这是我的代码abc.com
<$> p $ p>
$ sessionId = //使用auth_token从数据库获取。
/ *关闭上一个会话* /
session_destroy();
//设置新的ID。
session_id($ sessionId);
/ **开始新会话* * /
session_start();
我缺少什么?
我使用php与Symfony框架。不知道它是否与symfony会话处理相关。
确定。我解决了我的问题。
我必须在调用session_destroy()后删除旧的会话cookie。
这是我的完整代码,如果有人感兴趣:
$ sessionId = //使用auth_token从数据库获取会话ID
session_destroy();
$ this-> getResponse() - > setCookie('mycookie',null,time() - 3600);
session_id($ sessionId);
/ **开始新会话* * /
session_start();
$ this-> getResponse() - > setCookie('mycookie',$ sessionId,null,null,'mydomain');
感谢大家的帮助。
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.
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.
这篇关于同一会话,不同的域,设置会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!