php user login

How to prevent more than 1 person using the same user account to login?

(Especially when s/he not logs out but just closes the window)

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you are using PHP's built in sessions feature. You can get the Session's ID using $session_id = session_id();

When a user logs in you could take the session id that it generates and store it into a database under that user's account. Then on each page check to see if the current Session ID matches the one stored in the database for that user (If not, kill the current session and redirect them to a sign in page).

The session id will be different on each device they login using.

Does that make sense?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tyuretAuthor Commented:
It makes sense but I don't prefer to make a database query for every page. Is there another alternative?
You're going to need to make a record of it somewhere.  In a database, or in a file, it really doesn't matter.  But once the script ends at the end of the request, everything in memory is gone.  Even session information is written to disk.

A properly indexed sessions table isn't going to that big of a performance hit, but a hit none the less.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.