Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top