【问题标题】:Laravel4: Remembering AuthenticationLaravel4:记住身份验证
【发布时间】:2013-05-30 22:55:46
【问题描述】:

用户登录后,应重新进行身份验证,并且 Auth::check() 应返回 true。 但在用户个人资料上,它返回 false。有什么问题或遗漏?

Route::post('login', function() {
            $userdata = array(
                'username' => Input::get('user'),
                'password' => Input::get('pw')
            );
            if (Auth::attempt($userdata, true)) {
                return Redirect::to('profile');
            } else {
                return Redirect::to('/')->with('login_errors', true);
            }
        });

Route::get('profile', function() {
            return (Auth::check() ? 'logged in' : 'not logged in') . '<br />' .
                    (Auth::user()==null ? 'null' : Auth::user()->name);
        });

【问题讨论】:

    标签: php authentication laravel


    【解决方案1】:
    Route::get('profile', function() {
            return (Auth::check() ? 'logged in' : 'not logged in') . '<br />' .
                    (Auth::user()==null ? 'null' : Auth::user()->name);
        });
    

    我认为你的问题在于这个。 三元运算符的使用应如下所示 $action = (empty(var)) ? “默认”:空;

    Route::get('profile', function() {
            return (Auth::check()) ? 'logged in' : 'not logged in') . '<br />' .
                    (Auth::user()==null) ? 'null' : Auth::user()->name);
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2017-03-15
      相关资源
      最近更新 更多