Laravel 4 Auth works but does not stay logged in

混江龙づ霸主 提交于 2019-12-07 11:18:27

1.First Authenticate with :

     if (Auth::attempt($data)) {
  return Redirect::to('admin'); 
}

2.Then place this check to the page you have redirected your user after successful authentication In this case say 'admin' .

 if (Auth::check()) {
    echo "process";
    }
    else {
    return Redirect::to('login');
    }

I found the solution. Maybe this can help others:

After calling Auth:attempt you must not echo anything. You have do to a redirect. Does not make sense to me but solved the problem.

Event::listen('auth.login', function($user)
{
    echo 'user logged in'; 
});

Place this after Auth::attempt($data) and check.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!