First of all, it was a good study of ways to prevent password sharing.
My reaction to tracking user activity based on a query (i.e. the two-query solution proposed by @DaveRandom) was ahhhhh, no! As @CodeCaster notes, a likely case of premature optimization, but hey, we have a small (several thousand) but crazy user base that will be very happy with the start of the hockey season and the results of the game. ran for many years, do not want to rock the boat, this is a paid service, so the performance should be excellent.
OK solution:
The apache user has read / write access to the session files in the session directory. By writing down session_id during login, we have components to block shared password accounts. Upon successful login:
- Loop through stored session ids related to target account - if /path/to/session-id-file not empty, increment login counter - if login counter exceeds number of users allowed for a given plan: - delete all session files related to target account - lock the account and force a password reset
There is minimal overhead, the implementation is cake, the problem is solved.
Note. Initially, I thought it was impossible to access session directory files without creating a security loop; however, this is not the case (at least in my CentOS 5 setup warehouse). You cannot get a session_id that is not related to the current user session, but you can save this user session identifier and access the session file that stores their session from any user session (including blowing the file). The key has a session identifier to search for the corresponding / path / to / session file
source share