【发布时间】:2015-08-01 01:00:50
【问题描述】:
使用 5.0
在 config/session.php 我设置了'domain' => '.example.com',但它不起作用。我什至不能像这样在一个域上保持会话。
我的网站有很多子域:
vancouver.example.com
newyork.example.com
等等...它们托管在同一台服务器上并且是同一个 Laravel 应用程序(共享相同的存储目录)
我使用正确的凭据登录,然后应用程序重定向到站点上的另一个页面,此时我没有会话。 var_dump(Auth::user()) 显示 null 即使我使用正确的凭据登录。
storage/framework/sessions 在那里显示了 14 个不同的文件,它们都是给我的,我在开始测试之前清除了它们。
我将在下面附上我的 AuthController@postLogin 方法,如果 session.php 'domain' => null 可以正常工作
public function postLogin(Request $request)
{
$this->validate($request, [
'email' => 'required|email', 'password' => 'required',
]);
$credentials = $request->only('email', 'password');
if ($this->auth->attempt($credentials, $request->has('remember'))) {
Session::flash('message', 'You are now logged in.');
Session::flash('status', 'success');
if (str_contains($_SERVER['HTTP_REFERER'], '?goto=')) {
$params = explode('?', $_SERVER['HTTP_REFERER'])[1];
$target = explode('=', $params)[1];
} else {
$target = '/';
}
return redirect($target);
}
return redirect($this->loginPath())
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => $this->getFailedLoginMessage(),
]);
}
【问题讨论】:
-
我之前也遇到过同样的问题,只需要清除浏览器缓存。