使用5.0
在config/session.php我已设置'domain' => '.example.com'但它无法正常工作.我不能在这样的一个域上坚持会话.
我的网站有很多子域名:
vancouver.example.com
newyork.example.com
Run Code Online (Sandbox Code Playgroud)
等...它们托管在同一台服务器上,并且是相同的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([ …Run Code Online (Sandbox Code Playgroud) 我的网站中有一个子域名,例如:
http://example.ca
http://blog.example.ca
Run Code Online (Sandbox Code Playgroud)
博客只有拥有网址的人才能访问,也就是说,它不是公共或常识.我有一堆与此域名相关的路由,要求您登录.
我已经说过nav.blade.php,如果用户登录,则应该有一个下拉列表,如果没有,则不应该有下拉列表.
这一切都有效,http://blog.example.ca但是当我去的时候,http://example.ca我不再被认证了.
是否有任何方法可以让我在所有子域中进行身份验证?不只是那些需要我进行身份验证的控制器操作的人?