Create multiple logins in the same browser at same time

1.2k views Asked by At

I want to create multiple logins at a time on the same browser, like admin and user.

For that we are using different models like LoginForm.php and Adminlogin.php and different identity classes, i.e. User.php and Admin.php. But when we login with admin and at that time we want to login as a user admin gets logout and user gets login.

But I want to login both admin and user at same time. How to do that?

3

There are 3 answers

0
Mayank Pandeyz On

This is happening because, when a user is logged in by any role say admin, than internally like

$_SESSION['logged_in'] = true;
$_SESSION['user_id'] = logged in user id;

when you logged in again with a diff user then the value in $_SESSION['user_id'] is overrides by the new logged in user.

So with this approach you cannot make this happen.

The best way to achieve this is to provide a role change functionality after logged in.

0
harry On

you can add a prefix, like

SESSION['ADMIN_user_name']

is a admin user, other is normal user.

1
marche On

My recommendation would be to use Yii 2 Advanced Application Template. This way you can have a frontend and a backend, each with their own user component for login and it's own session.

This way you can also separate views and controllers that need to be exclusive to normal users or admin users, while also sharing through common models and modules that are used by both types of users.