在线用户,CodeIgniter和会话 [英] Users Online, CodeIgniter and Sessions

查看:49
本文介绍了在线用户,CodeIgniter和会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我正在使用CodeIgniter作为我与几个我的伙伴正在从事的项目的MVC。我们还使用CI的数据库会话支持。有了这些,我确实知道已经存在谁在线的概念,但是每个概念都不能真正满足我们的需求。我们推出的服务是一个独立的SaaS式系统,但是与此同时,我们也允许用户彼此通信。这样,我们就可以让他们与他们希望共享的人共享具体信息,例如谁在何时何地在线等等。因此,我知道CI的会话与IP一样,用户登录时也是如此。

Ok, I am using CodeIgniter as my MVC for a project I am working on with a couple buddies of mine. We are also using CI's Database Session support. With that I do know there are "Who's online" concepts already in existence but none of them really apply to our needs per say. The service we are rolling out is a stand alone SaaS like system however at the same time we are allowing our users to communicate with one another as well. With that we let them share with who they wish specifically information like who's online when, where, etc.. So that said I know CI's sessions catch the IP, as do we when a user logs in.

所以我想知道的是,认为我可以利用会话数据的本质,将会话数据库中的ip与已登录的ip进行比较,是否是一个合理的想法?我自己的小谁在线上,专门针对通过我们的服务彼此友好的人。如果这是一个好主意且有潜在的创意,那么您对此有何建议呢?我只问是因为我不是100%通过CI进行的会话如何工作,所以我不确定它是否会像我当前想象的那样对我有利。

So what I am wondering is, is it a plausible idea to think I can exploit the session data for what it is, to compare the ips in the session DB against those logged in to in a sense build up my own little "Who's online" specific to people who are "friendly" with one another through our service. If it is a good and potential idea, what would any of you suggest as a means of tackling it and handling it for this type of display? I only ask cause I am not 100% how the sessions via CI work so I am not sure if its going to work in my favor like I am currently imagining.

如果但是我的想像力消失了,否则有什么好办法解决这个问题?

If my imagination is however running away with me, what would be a good way to tackle this otherwise?

EDIT
登录后在2台计算机上,我看到数据库中的CI会话具有2个具有相同IP的IP,所以我最初的想法似乎有缺陷。

EDIT After logging in on 2 computers I see that the CI session in the DB has 2 with the same IP so my initial thought patter seems to be flawed.

还要感谢Down投票,无论您是谁,您至少可以在评论中说出为什么,我非常想知道如何实现这个想法,但是我无法获得反馈?如果您知道这里有一篇文章或帖子可以为我提供帮助,那么至少可以指出我的看法,从而使我的搜索与我在此处试图解释的内容无关。

Also thanks for the Down vote, whoever you are, you could have at the least said why in a comment, I am seriously curious to know how to achieve this idea, but I can't get feedback on it? If you know of an article or post here that can help me out then at least point me towards that, cause my searches yield nothing relevant to what Im trying to explain here.

推荐答案

基本上,您想检查 _ci_sessions 表(或您的名字)来查找的记录。 last_activity 列在当前时间的一定范围内(5分钟,10分钟等)。使用HTTP,无法知道某个人放弃会话的确切时间(除非他们明确注销,并且您自己销毁了会话)。您可以使用套接字来完成此操作,但这通常对这样的东西来说是过高的。

Basically, you want to check the _ci_sessions table (or whatever your name is) for records where the last_activity column is within a certain range of the current time (5 minutes, 10 minutes, etc.). With HTTP, there's no great way of knowing the exact moment someone abandoned their session (unless they explicitly logout, and you destroy the session yourself). You could do it with sockets, but that's usually overkill for something like this.

在获得潜在会话列表之后,您仍然需要遍历每个(记住要取消序列化 user_data 列!),以找到具有正确userdata键/值的内容,以根据您的身份验证系统来构成登录。我首先要做的是得到概念证明,然后找到一种方法来缓存几个请求的结果,因为它毕竟不是请求级的,您最好在没有每个请求的额外负担的情况下做得更好。

After you get a list of "potential" sessions, you'd still need to loop through each (remember to unserialize the user_data column!) to find the ones that have the correct userdata key/value to constitute a "login" based on your authentication system. I'd do that first to get proof of concept, then find a way to cache the result across a few requests, as it's not request-level accurate anyway, You'd do better without the extra load on every request.

这篇关于在线用户,CodeIgniter和会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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