Laravel 4 Auth有效,但无法保持登录状态 [英] Laravel 4 Auth works but does not stay logged in

查看:373
本文介绍了Laravel 4 Auth有效,但无法保持登录状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Laravel 4 App中,我使用了Auth功能.

In my Laravel 4 App I use the Auth functionality.

我将登录表单提交至:

$data = array(
'email'     => Input::get('email'),
'password'  => Input::get('password')
);

if (Auth::attempt($data)) {
    echo 'SUCCESS!';
} 

这将输出SUCCESS,因此一切正常.但是,如果我下次调用其他方法,则该用户未登录:

This outputs SUCCESS, hence everything works. But if I next call another method the user is not logged in:

if (Auth::check()) {
echo "logged in";
}
else {
echo "not logged in";
}

这将输出未登录".我尝试添加true来尝试记住登录名,但这并没有区别.我还有另一个运行Auth的Laravel应用,效果很好.

This outputs 'not logged in'. I tried to add true to attempt to remember login but it does not make a diference. I have another Laravel App with Auth running that works perfectly.

任何想法是什么原因?

推荐答案

我找到了解决方案.也许这可以帮助其他人:

I found the solution. Maybe this can help others:

致电Auth:attempt后,您绝对不能 echo任何东西.您已经对redirect做过.对我来说没有意义,但解决了问题.

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.

这篇关于Laravel 4 Auth有效,但无法保持登录状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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