laravel and multi-sessions from the same browser

后端 未结 8 1213
眼角桃花
眼角桃花 2020-12-02 21:00

In our web app, If I use a single browser, login to our application as user A, open another tab and login as user B - User A loses his session data. I assume this is due to

相关标签:
8条回答
  • 2020-12-02 21:36

    Multi userlogin with same browser like google add account. for that you need follow some steps and re-write auth library which provided by the Laravel,

    Steps

    Tack backup of your Auth file.

    Change all session store functionality to store it first in array and then store that array to session

    Now you need to create the new session variable which will store the current user instance id like user 0 1 2 ...

    Now you need to change all the function from you will get the values from the session you need to check if the session object is empty then user is logout else you need to get data of the user base on the user instance.

    You need to change your instance when user want to switch from one account to another.

    0 讨论(0)
  • 2020-12-02 21:36

    The easiest is just a URL based sessionID which could be a security issue depending on how your application is designed, especially when sharing urls with non-expired sessions.

    Since L5 doesn't support php native sessions anymore, you'll have to use a custom provider like below:

    This will use sessionID in the url for laravel V5:

    https://github.com/iMi-digital/laravel-transsid

    Basically the session is URL based, so you can just login in a different tab and get a new sessionID, and that person can easily do a "open page in new tab" to have two pages of the same user if needed as well.

    The library above locks the session to the IP and User Agent so link sharing won't accidentally leak a session.

    0 讨论(0)
提交回复
热议问题