在会话中更改域后,Laravel Auth :: login()不持久 [英] Laravel Auth::login() doesn't persist after change domain in session

查看:64
本文介绍了在会话中更改域后,Laravel Auth :: login()不持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,在我更改session.php中的domian之前,我的Auth :: login()工作正常,它将保留cookie,因此他们无需再次登录.当我的一些朋友告诉我,当他们单击登录(来自Facebook)时,它将以某种方式在AbstractProvider.php中返回InvalidStateException.

previously before i change the domian in session.php,my Auth::login() is working fine and it will persist the cookie so they dont need to login again. When some of my friend told me that when they click login (from facebook), it will somehow return InvalidStateException in AbstractProvider.php.

我在Google周围徘徊,知道Cookie可能引起某些问题,解决方案是将session.php中的域从null更改为我的域(例如myapps.com).

I google around knew there maybe some issue cause by the cookie, and the solution is changing the domain in the session.php from null to my domain (example myapps.com).

在我更改为myapps.com之后,不再发生invalidstateException,但它不会保留我的登录信息. 6至12个小时后,它要求我再次登录.

After i've change to the myapps.com, invalidstateException no longer occurs but it wont persist my login. After a 6 - 12 hours, it required me to login again.

下面是我的代码(我相信在更改会话之后,我的代码是正确的,并且登录将不再持续).

Below is my code ( i believe my code is correct just after i've change the session and the login wont persist anymore).

$UserLogin = User::where('facebook_id', '=', $user->getId())->first();
Auth::login($UserLogin, true);

推荐答案

核心问题是您的浏览器存储了来自多个具有相同Cookie名称的域的两个Cookie laravel_session;当您发出请求时,两个同名的cookie都将发送到服务器.

The core problem is that your browser stores two cookies from multiple domains with the same cookie name called laravel_session; when you make a request, both cookies with the same name are sent to the server.

在您的config/session.php中:

//change this
'cookie' => 'laravel_session'

//and this
'domain' => 'my_domain'

通过更改cookiedomain的名称,可以通过使用新名称存储新的cookie来解决此问题.

By changing the name of the cookie and domain, you'll get around the problem by the storing new cookies under a new name.

这篇关于在会话中更改域后,Laravel Auth :: login()不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆