简体   繁体   English

不同文件夹的会话管理

[英]Session Management for different folders

I am working on an application which contains two different portals (admin and members). 我正在开发一个包含两个不同门户(管理员和成员)的应用程序。 http://localhost/app/ is used for the members login and http://localhost/app/admin is used for admin's login. http://localhost/app/用于成员登录,而http://localhost/app/admin用于管理员登录。

When I log in into members and admins portal both works fine but if I logout from one portal another portal logged out automatically. 当我登录到成员和管理员门户网站时,两者都可以正常工作,但是如果我从一个门户网站注销,则另一个门户网站会自动注销。

I checked that the session file created in /tmp/ directory stores the sessions information for both the portals in a single file which causes the above problem. 我检查了在/tmp/目录中创建的会话文件是否将两个门户的会话信息存储在单个文件中,这会导致上述问题。 The work around I think is to save the session information of both portals in different directories. 我认为,解决方法是将两个门户网站的会话信息保存在不同目录中。 I searched a lot for this but didn't get any resolution :( 我为此进行了大量搜索,但没有得到任何解决方法:(

Please help. 请帮忙。 Thanks in advance! 提前致谢!

You can destroy session elements individually instead of just calling session_destroy(); 您可以单独销毁会话元素,而不仅仅是调用session_destroy(); .

For example, use $_SESSION['logged_a'] for the admin and $_SESSION['logged_u'] for the user. 例如,对管理员使用$_SESSION['logged_u'] ,对用户使用$_SESSION['logged_a']

And then, depending on where you logout from, do unset($_SESSION['logged_a']) or unset($_SESSION['logged_u']) 然后,根据您注销的位置,执行unset($_SESSION['logged_a'])unset($_SESSION['logged_u'])

I hope this helps! 我希望这有帮助! Good luck! 祝好运!

PHP sessions work on a per domain basis as they use cookies. 由于PHP会话使用Cookie,因此它们在每个域上均起作用。 If you want to have separate login systems for each directory your application will have to deal with that. 如果您希望每个目录都有单独的登录系统,则您的应用程序必须处理该登录系统。 A working approach would be to store the session id in a database along with a reference to which portals the session is logged in to. 一种可行的方法是将会话ID与会话登录到的门户的引用一起存储在数据库中。 When a user logs out of one portal, rather than destroying the session, delete the record showing that the session is logged into that portal. 当用户注销一个门户网站而不是破坏会话时,请删除记录,表明该会话已登录到该门户网站。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM