简体   繁体   English

如何在Codeigniter中同步数据库和会话?

[英]How to sync the database and the session in codeigniter?

I got a problem, when the user is logged, and I assign the user their id, for example, 126. But when I doing maintain, or delete some banned user, for example, the user id 126 will remove from the database, but the user 126 still have the number 126 in his session. 我遇到了一个问题,当用户登录时,我为其分配了ID,例如126。但是,当我进行维护或删除某些被禁止的用户时,例如,用户ID 126将从数据库中删除,但是用户126在其会话中仍具有数字126。 How can I 'delete' his session content when I detect my database have user id is deleted? 当我检测到数据库中删除了用户ID时,如何“删除”他的会话内容? Thank you. 谢谢。

Sounds to me like you are worried about ID 126 being blocked even if it gets assigned to a new user. 听起来像是您担心ID 126被阻止(即使将其分配给新用户)也是如此。

Shouldn't be a problem, cause IDs in those cases (usally) get created in an auto increment fashion and the DB (MySQL for sure, most others probably, too) chooses the next higher value to the highest ever generated value in such an auto-increment field. 应该没问题,在这种情况下(通常)会导致ID以自动递增的方式创建,而DB(肯定是MySQL,也可能是大多数其他数据库)会在这种情况下选择下一个较高的值,以达到有史以来的最高值自动递增字段。

So if the highes assigned value was 1234, then you can delete what you want, the next value is going to be 1235. 因此,如果最高分配值是1234,则可以删除所需的值,下一个值将是1235。

So your problem is not really a problem as it seems to me. 因此,在我看来,您的问题并不是真正的问题。

There are 2 solutions that I can think of this, 我可以想到两种解决方案,

1.) Store the user credentials in the db, every time the user makes an action you can check for credentials then kick the user out if already banned. 1.)将用户凭据存储在数据库中,每次用户执行操作时,您都可以检查凭据,如果已被禁止则将其踢出。 I don't think its 我不认为

2.) cache the logged in users, the cache should be global so the banned user's session can be checked 2.)缓存已登录的用户,缓存应该是全局的,以便可以检查被禁用户的会话

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

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