문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top