PHP 登录系统,如 yahoo Messenger

发布于 2024-10-01 17:27:21 字数 119 浏览 0 评论 0原文

我将使用 php 创建登录身份验证,要求是:一个用户名帐户不能同时登录,如果发生这种情况,第一个登录用户应自动注销。就像雅虎通一样。这个概念实际上是怎样的?,使用 PHP 实现此目的的最佳技巧是什么?

谢谢。

I would create a login authentication using php, The requirement is : one username account can't login at the same time, if this occur the first login user should logout automatically. Just like yahoo messenger do. How is the concept actually ?, What the best trick to do this with PHP ?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦回梦里 2024-10-08 17:27:21

您需要将上次登录的会话 ID 存储在数据库中。当用户下次登录时,旧会话将失效,并将新创建的会话 ID 存储在数据库中。例如:

$old_sess_id = /* read saved session ID from database */;
session_id($old_sess_id);
session_start();
session_regenerate_id(true); // "true" deletes old session
$new_sess_id = session_id();
/* store new session ID in database */

You need to store the session ID of the last login in your database. When a user logs in the next time, you invalidate the old session and store the newly created session ID in the database. For example:

$old_sess_id = /* read saved session ID from database */;
session_id($old_sess_id);
session_start();
session_regenerate_id(true); // "true" deletes old session
$new_sess_id = session_id();
/* store new session ID in database */
奶气 2024-10-08 17:27:21

卡萨布兰卡是对的......

此外,您不需要同时保存新旧会话。在你的数据库中只有一个会话。
当用户登录时更新您的会话值。在检查会话的代码之后。之前的登录将自动失效。

casablanca is right...

additionally you dont need to save both old and new session. just have one session in your db.
when the user logs in update your session value. after code for check session. The previous login will be automatically invalidated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文