开发者

How to achieve session management purpose like google in PHP?

I mean开发者_开发知识库 you can login both https://mail.google.com/ and https://mail.google.com/a/company.com at the same time.

The projects I've attended so far haven't involved such kind of logic,how can these two url under the same domain use different $_SESSION?


I think there is not inbuilt session management feature in PHP. You can use variable specific management in session. for eg. one login from https://mail.google.com/ then store all it's session data in $_SESSION['gmail'][X] , $_SESSION['gmail'][Y],$_SESSION['gmail'][Z]

and then in when another user login from https://mail.google.cpm/a/company.com then store all it's session data in $_SESSION['company'][X],$_SESSION['company'][Y],$_SESSION['company'][Z]

so by this, you can separate those two sessions from each other.


Those two URLs share the same domain. Only the subfolders are different. Usually with PHP, the cookie which saves the session id is valid for the whole domain and not only a specific subfolder. So there should be no problem using the session data with the same domain.


Maulik Vora's answer will work, but another way to do it is to configure PHP to used URL-based session ID passing. That way every tab or window has a separate session. See this page for information on how to do it, and why you may or may not want to. Here's the docs for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜