dongsou3041
dongsou3041
2010-11-13 06:09
浏览 31
已采纳

PHP登录系统,如yahoo Messenger

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.

图片转代码服务由CSDN问答提供 功能建议

我会使用php创建登录验证,要求是:一个用户名帐户无法同时登录 ,如果发生这种情况,第一个登录用户应自动注销。 就像雅虎信使一样。 实际上这个概念是怎样的?用PHP做这个的最好的诀窍是什么?

谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douxin1956
    douxin1956 2010-11-13 06:28
    已采纳

    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 */
    
    点赞 评论
  • drsh30452
    drsh30452 2010-11-13 08:35

    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.

    点赞 评论

相关推荐