Add a column for a session ID to your users table. When someone logs in, update their session ID in the table. On each page load, check if the session ID matches the one in the database. If not, destroy their session, logging them out.
When "B" logs in with "A"s credentials, those credentials are updated with "B"'s session ID. When "A" who is still logged in from earlier tries to view another page, "A"'s session ID won't match the one in the table, so you destroy it and "A" is now logged out while "B" is still logged in.