Laravel auth session cookie not sending

apache, cookies, json, laravel, php

Solution

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.

Problem

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() )); } ``` 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. 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.

Original source