久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

來自同一瀏覽器的 Laravel 和多會話

laravel and multi-sessions from the same browser(來自同一瀏覽器的 Laravel 和多會話)
本文介紹了來自同一瀏覽器的 Laravel 和多會話的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在我們的 Web 應用程序中,如果我使用單個瀏覽器,請以用戶 A 的身份登錄我們的應用程序,打開另一個選項卡并以用戶 B 的身份登錄 - 用戶 A 會丟失他的會話數據.我認為這是由于用戶代理創建的共享 cookie.有沒有辦法用用戶名連接它的名字?以便會話可以在同一臺機器上使用相同瀏覽器的并發登錄用戶之間共存?

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 a shared cookie made out with the user-agent. Is there a way to concat its name with a username? so that sessions can co-exist between concurrent logged in users using the same browser on the same machine?

我們使用 Laravel 5.有什么解決辦法嗎?

We use Laravel 5. Is there any way around it?

推薦答案

Laravel Session 背景

會話

跳過此部分以獲得快速簡單的解決方案

在 Laravel 中,會話 cookie 是通過 IlluminateSessionSessionManager 類創建的,即通??過 buildSession 方法:

In Laravel, session cookies are created via the IlluminateSessionSessionManager class, namely through the buildSession method:

SessionManager::buildSession

protected function buildSession($handler)
{
    if ($this->app['config']['session.encrypt']) {
        return new EncryptedStore(
            $this->app['config']['session.cookie'], $handler, $this->app['encrypter']
        );
    } else {
        return new Store($this->app['config']['session.cookie'], $handler);
    }
}

在這個方法中,我們可以清楚地看到會話的名稱來自我們的configsession.php,特別是這一行:

In this method we can clearly see that the name of the session comes from our configsession.php, looking in particular this line:

session.php

'cookie' => 'laravel_session', # ~~ ln 121 at time of writing

好的,但這并沒有多大幫助,改變它,改變它無處不在,正如在配置中進行的評論所指出的那樣.

Ok, but that doesn't help a lot, changing this, changes it everywhere, as noted by the comment proceeding it in the config.

此處指定的名稱將在每次新會話 cookie 時使用由框架為每個驅動程序創建.

The name specified here will get used every time a new session cookie is created by the framework for every driver.

即使我們可以傳遞一些動態值,例如:

And even if we could pass it some dynamic value, something like:

'cookie' => 'laravel_session' . user()->id,

這會產生一個矛盾的、時間結束的、宇宙內爆的結果,因為您從通過 session 訪問的 user 請求 id通過 cookie 名稱 laravel_session 查找..(腦殘)

This creates a paradoxical, time ending, universe imploding outcome because you are requesting the id from the user which is accessed via the session looked up by the cookie name laravel_session.. (mindblown)

讓我們離開 SessionManager 而它是 session.php 配置.我們可以從上面看到,無論我們如何處理,我們所有的會話信息都將歸入該單個 laravel_session 鍵下.

Let's leave SessionManager and it's session.php configuration alone. We can see from above that regardless of how we approach this, all our session info will be fall under that single laravel_session key.

也許 Guard 會有更多信息.

Maybe Guard will have some more information.

Guard 是您對應用程序進行身份驗證的關鍵,也是使 Laravel 能夠快速創建應用程序的眾多因素之一.

Guard is your key to auth into your app, and one of the many things that makes Laravel awesome for quickly creating applications.

要查看的方法是Guard::user().

Guard::user() 在一些初始緩存和注銷檢查之后做的第一件事就是會話檢查.

One of the first things Guard::user() does after some initial cache and logged out checking, is a session check.

Guard::user()

$id = $this->session->get($this->getName()); 

所以在這里,Laravel 正在獲取與 getName() 的結果匹配的會話值 - 太棒了 - 我們需要做的就是 mod getName() 返回一個值,讓我們來看看那個方法:

So here, Laravel is fetching the session values that match the result of getName() - awesome - all we need to do is mod getName() to return a value, let's take a took at that method:

Guard::getName()

public function getName()
{
    return 'login_'.md5(get_class($this));
}

這很直接.$this 指的是 Guard 類,因此 md5 將有效地始終相同(如果有人知道 md5 背后的為什么"每次都相同的類名,請發表評論).

That's pretty straight forward. $this refers to the Guard class, so the md5 will effectively always be the same (if anyone knows the 'why' behind md5'ing the class name which would be the same each time, leave a comment).

有幾個地方應該更新這個,比如getRecallerName.

There are a few places where this should be updated, such as getRecallerName.

因此,從這里開始,您可以擴展核心 Guard 類并拼接您的 getName 和 getRecallerName 方法.

So from here, you can extend the core Guard class and splice in your getName and getRecallerName methods.

您可能希望圍繞此包裝一些服務提供者,編寫一些單元測試,甚至可能覆蓋原始身份驗證管理器.

You will probably want to wrap some service provider around this, write some unit tests, possibly even overwrite the original auth manager.

天哪,這看起來工作量很大"

"Geez, that seems like a lot of work"

肯定是比利,肯定是"

https://www.youtube.com/watch?v=dTxQ9yhGnAg

看下一部分

Ollie Read 已經創建了一個解決方案,可在此處找到:

Ollie Read has already created a solution, found here:

https://github.com/ollieread/multiauth

我鼓勵您查看一下,尤其是自定義 Guard 類,它使用自定義 getName 方法擴展了核心 Guard.

I encourage you to have a look, especially the custom Guard class which extends core Guard with custom getName methods.

這篇關于來自同一瀏覽器的 Laravel 和多會話的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 亚洲福利一区 | 国产亚洲网站 | av中文天堂 | 中文字幕99| 日韩精品一区二区三区中文在线 | 日韩1区| 精品久久香蕉国产线看观看亚洲 | 成人在线观看免费视频 | 午夜电影网 | 国产在线视频在线观看 | 国产精品自拍啪啪 | 91久久精品一区二区二区 | 中文在线观看视频 | 日韩三片| 中文在线视频 | 日韩一区二区三区在线观看视频 | 欧美日韩在线免费观看 | 91电影院| 欧美成人一级 | 爱综合| 国产精品视频不卡 | 黄色网址大全在线观看 | 欧美性精品 | 成人在线视频一区二区三区 | 国产午夜精品理论片a大结局 | 久久com | 九九综合九九 | 99精品网 | 亚洲综合三区 | 精品中文字幕视频 | 午夜影院在线播放 | 国产福利在线 | 伊人超碰| 91 在线| 美女逼网站 | 超碰最新在线 | 一二区视频 | 97人人爱 | 伊人伊成久久人综合网站 | 亚洲精品一区二区三区蜜桃久 | 一区二区视频在线 |