Question

I'm working on a project that will be subscription based and the accounts need to have a limit of 2 concurrent sessions per user.

I have some ideas but am not entirely sure how to do this and maybe there is some built in way to do this that I am unaware of.

Any suggestions are welcome.

I was thinking that if I switch the session driver to database and then extend the Auth or Session driver to store some extra info in the sessions table, like user id, that this would be somewhat easy to do.

Not entirely sure how to do this either though so any help would be greatly appreciated!

No correct solution

OTHER TIPS

I think you talking about multi login from different IPs/Devices? Thats what i think about right now. You cannot count "Browser Tabs" or something like that ...

So, if this is your case your solution is such easy. Bind any user login on an active record in a an database or an other persistence.

DB-Model:

userSession (
    'id', // primary key
    'userId', //foreign key
    'sid', //unique session id
    'ip', //unique user id or uniqure device (I preffer IP!)
    'login', //datetime
    'lastClick' //datetime
);

An active session is open if a active record in db for that user exists. You need to check for the given db user record on any user action (HTTP-Request I think). You are able to count active user session for one user now. You are also able to kick user now by delete the depending userSession record.

This can be achieved either with sql using the UPDATE in a table and have a column set to active sessions and php check if the sessions are more than 2, if they are deny login, or the other way.

<?php
function checkSessions(){
mysql_connect(data);
$q = "SELECT * FROM users WHERE username=$username && password=$password";
 while($row = mysql_fetch_array($q)){
 if($row["Active Sessions"] >2){
 die("There are too many people using the account right now");
}

You get the idea this is a sample.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top