Login System design to allow each user to be logged in on one machine at a time

authentication, javascript, php

Solution

Some Instant Messengers (that can work only with one logged in endpoint) have a nice way of sorting out such conflicts. They show a message like

You are already logged on from `<COMPUTERNAME>`

(in case of a web app, that would be `<IP/Browser>`)

and give you a choice between

- either leaving that logon alive (and not log on from the machine you're on), or

- ending the existing logon (and logging on on the current machine).

This is technically the most challenging, but definitely the most friendly way - it ensures a user has only one session running, without being too obvious about it. And there is no bad blood with users unable to log in because they forgot to log out at work, etc.

Problem

How should I design a login system so that each username can only be logged on in one place at a time? I want to keep users from giving their username to someone else to login so they can avoid paying for each user. If a user is already logged in and tries to log in on another machine should I block the 2nd login (which could be a problem if the user was logged on at work and then tried to get on at home)? Or should I allow the 2nd login and end the 1st login? Or does anyone have a better suggestion?

Original source