Logout if user is already logged in

I am planning a paid service

User pays to me I create a uid and pwd for him.

I do not want him to share his uid and pwd to anyone.

“A” has logged in with his credentials. Now “B” logs in with "A"s credentials. I want to log out A and log in B.

How to acheive this is php.

How to logout a already logged in user.

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.