0

Possible Duplicate:
PHP /SESSION: Login one per user?

I need to know how to let one user login once.

halfer
  • 19,824
  • 17
  • 99
  • 186
Bobj-C
  • 5,276
  • 9
  • 47
  • 83
  • Store a value in the database, when they login set it as true. Check it everytime they attempt to login that it is false..? – Elliott Apr 17 '11 at 19:07
  • @Elliot: I'd recommend storing the `session_id()` value - that way, it's far easier to make sure that account is logged into that computer. When they login elsewhere, it changes, so comparing the stored value with the one held in the browser will turn out false. – Bojangles Apr 17 '11 at 19:15

1 Answers1

5

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?

Jason Mitchell
  • 299
  • 1
  • 4
  • 5
    ..and if the session timeouts the user will never be able to login again because he has a new session id.. – halfdan Apr 17 '11 at 19:55
  • 4
    killing the previous session and keeping the current session would be better :) – Hugo Jul 30 '13 at 13:51