开发者

PHP Login system like yahoo Messenger

I would create a login authentication using php, The requirement is : 开发者_如何学Pythonone 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.


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 */


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜