Laravel AUTH不发送会话cookie [英] Laravel auth session cookie not sending

查看:424
本文介绍了Laravel AUTH不发送会话cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个pretty基本Laravel登录脚本

So I have a pretty basic Laravel login script

$email = Input::get('email');
$password = Input::get('password');
if(Auth::attempt(array('Email'=>$email, 'password'=>$password), true)){
    return Response::json(array('success' => true,'logged_in'=>Auth::check() ));
}

我登录一个有效的电子邮件和密码。我已经把LOGGED_IN响应数组中只是作为一个测试,它的尝试后返回true。然而,laravel_sessioncookie不会返回的响应,和后续调用没有看到用户的登录状态。这只是发生我的生产服务器,我的本地环境和测试环境没有问题,都工作的。

I'm logging in with a valid Email and Password. I've put "logged_in" in the response array just as a test, and it returns true after the attempt. However, the "laravel_session" cookie is not returned on the response, and subsequent calls do not see the user as logged in. This is only happening on my Production server, my local environment and test environment both work with no issue.

另一个说明,我注意到,响应:: JSON是返回,而不是应用程序/ JSON的text / html的MIME类型。我不知道是什么导致的,所以我只是设置jQuery.ajax数据类型为JSON绕过它。这只是发生我的生产服务器上也是如此。我都出在这一个想法,将是一些帮助非常感激。

As another note, I noticed that Response::json is returning the text/html MIME type, instead of application/json. I wasn't sure what was causing that, so I just set the jQuery.ajax dataType to "json" to get around it. This only happens on my production server as well. I'm all out of ideas on this one, and would be very thankful for some help.

推荐答案

男人,我忘了我问这个问题。但我没有最终找到了答案,这是非常愚蠢的但很重要的,所以现在我会回答它。

Man, I forgot I asked this question. But I did end up finding the answer, and it was really silly but important, so I'll answer it now.

在我的配置文件中的一个深,有人(可能是我)已经插入&LT前的空间;一个PHP文件的开始。这是分别设置任何头前,所以他们不允许更改(意味着没有饼干可以设置),因为数据已经写入到输出流。所以,如果你正在寻找为什么发生这种情况给你,一定要寻找那些。

Deep in one of my configuration files, someone (probably me) had inserted a space before the <? beginning of a PHP file. This was before any headers were set, and so they weren't allowed to be changed (meaning no cookies could be set) since data had already been written to the output stream. So if you're searching for why this is happening to you, make sure you look for that.

这篇关于Laravel AUTH不发送会话cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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