When a user logs in all logged in users must be notified in real-time.
With html5 you can use websockets. However, prior to that there are several different techniques known as comet
The most naive implementation is old school polling, where each client would poll the server every X seconds using ajax asking for a list of all logged in users. Simultaneously, this can be used as a heartbeat to verify that the user is still active because some users may not have logged out using the log out link and simply closed the tab.
One step up is called long polling where instead of polling every X seconds, a single ajax request is sent and the server only responds once some event has occurred ('someone logs in'). Once the client receives a response it immediately sends another ajax request to reestablish the connection.
It is worth understanding the underlying details, but there is no need to reinvent the wheel. I use a service called pusher. It also has webhooks to alert you once a connection has been terminated which can be useful for determining when the user has closed the tab without logging out.
How do these third party services work?
They require you to add a js snippet to your html page which will establish a connection with their servers. Web sockets are used if supported by the browser otherwise one of several fall back methods can be used such as comet or flash for older browsers.
When you wish to send information, you simply make a post request to the service which will then alert the intended client over the already open connection.