在本地主机上,两个不同的项目共享同一会话 [英] On localhost, two different projects share the same session

查看:39
本文介绍了在本地主机上,两个不同的项目共享同一会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的本​​地主机是XAMPP。这两个项目基本上是相同的代码,至少是登录模块。这些项目是使用Codeigniter构建的。

My localhost is XAMPP. The two projects are basically the same code, at least the login module. The projects are built with Codeigniter.

我的问题是,例如,如果我登录到Project A,然后发现我自动登录了Project B,太。

My problem is, for example, if I logged in on Project A, then I found I'm automatically logged in on Project B, too.

这两个项目没有使用相同的数据库,但是它们的登录代码是相同的。当用户访问页面时,我将首先检查变量 $ this-> session-> isLoggedIn ,如果是这样,我会将页面重定向到用户页面。我确实发现他们使用相同的会话ID。

The two projects does not use the same database, but their login code is the same. When the user visit the page, I will check the variable $this->session->isLoggedIn first, if so, I will redirect the page to the user page. I do find that they use the same session id. Is this a common issue on the localhost, since they share the same domain, or I made a mistake?

推荐答案

同时设置会话,您需要区分 会话基于项目
这样的标识

while set session you need to differentiate the session Based on project for your identification like this

$ this-> session-> set_userdata('project_A_username','usernamehere');

$ this-> session-> ; set_userdata('project_B_username','usernamehere');

php会话在您的所有项目中都很常见。

php session is common for all your project . so you have to differentiate.

OP评论:如果是这样,因为它们不在同一个域中,这将不会在实时环境中发生吗?

OP comments : If so, this will not happen in the live environment, since they are not under the same domain?

是的,因为它们位于不同的域中,所以不会发生。

yes it will not happen .since they are in different domain .

这篇关于在本地主机上,两个不同的项目共享同一会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆