Laravel Session Not Saving

 David

I just launched a new website using Laravel but ran into a problem where session was not being persisted.
Every time I post a form, it would redirect back to the requesting page and I could not figure out why...
I spent HOURS googling and combing through articles after articles but couldn't find the answer

I added a test route with the following logic below and found out that it was creating a new session on each request!

Route::get('test', function()
{
   echo 'Session ID = '.Session::getId();
});


After figuring out that a new session id was being created for each request, I modified my google search keywords then found better search result and ultimately this article that helped me solve this problem...

As mentioned on the article, I had a blank space before <?php tag in app/config/app.php file!!!! and this one white space caused it to create a new session every time...

If you are experiencing this issue, please check all the php files in config folder, such as app.php, database.php, mail.php, session.php, etc, and if they have any white space or line break before <?php on the first line then it will recreate session on every request... unbelievable

Thank you rpg999 for figuring out this problem and sharing on laravel.io 7 years ago
Go Back to List Page

Leave a comment

Name : Comment : view emoticons
Please consider signing up for our website.
If you sign up and log in:
  •   You can avoid the "I'm not a robot" captcha when commenting
  •   You can also avoid typing your name every time
  •   You can upload a picture for each comment
  •   You can change or delete your comment within 1 hour
  •   You can track all the comments you posted on this site
  •   You can read blog posts that are only open to members
  •   You can look up blogs using the search feature
  •   More privileges for our friends & families coming...

OK, Sign me up!

Emoticons are a great way to visually express how you feel.
However, there are times when unintended content is converted to emoticon because the content happens to have one of the emoticon symbols. That's why it's always good idea to preview your comment before posting and when you see this type of problem, you can indicate NOT to auto convert.