Laravel会话在每个负载重新生成 [英] Laravel sessions regenerating on every load

查看:108
本文介绍了Laravel会话在每个负载重新生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多问题,我真的找不到解决方案。

I'm having a lot of problems and I really can't seem to find a solution.

昨天,我完成了在一个流浪汉盒子上做一些工作在Laravel。当我关闭电脑时,登录功能工作正常。

Yesterday, I finished up doing some work on a vagrant box in Laravel. When I shut down the computer, login functionality was working fine.

今天打开一切,我发现会话不再工作。

On opening everything up today I find sessions are no longer working.

我尝试了所有我可以想到的,但我现在无法登录,闪存数据不工作。

I've tried everything I can think of but I cannot log in now and flash data doesn't work.

每个页面加载一个新的会话创建 - 例如使用本机驱动程序,如果我登录,它创建两个会话 - 一个用于登录页面,一个用于发布的登录页面。

Every page load a new session is created - e.g using the native driver, if I login, it creates two sessions - one for the login page, and one for the posted login page.

一个数据库驱动程序我得到相同的结果。每次我点击登录,我得到另外两行会话数据

If I use a database driver I get the same result. Every time I click login, I get a further two rows of session data

我不能告诉cookie驱动程序发生了什么,但我试过它,它不是工作。

I can't tell what's happening with the cookie driver but I've tried it and it's not working.

我已经在Chrome和IE尝试,也不会登入。我尝试删除存储文件夹的内容多次,并在浏览器端清空Cookie。我确实认为这可能是与vm和本地机器上的时间不同,但它们是同步的。

I've tried in Chrome and IE and neither will login. I've tried deleting the contents of the storage folder multiple times, and emptying cookies on the browser side. I did think it may be to do with the time being different on the vm and the local machine but they're synchronised.

任何想法可能导致这种情况?之前有人遇到此问题吗?

Any ideas what could be causing this? Anyone come across this issue before?

编辑:我现在也重新创建了虚拟机,问题仍然存在

edit: I've also now recreated the virtual machine and the problem still exists

第二次编辑:我现在从头开始使用一个digitalocean VPS与相同的结果。

second edit: I've now started from scratch using a digitalocean VPS with the same results.

我已经删除了我的路由文件中的一切,现在有以下

I've stripped out everything in my routes file and all it now has is the following

<?php

Route::get('/sess/set/{value}', function($value) {
    Session::set('testv', $value);
Return 'Set ' . $value . ' - ' . Session::get('testv');
});

Route::get('/sess/get', function() {
    Return 'Get ' . Session::get('testv');
});

我访问第一页,它显示我在会话中输入的值。命中第二页,你只得到没有任何会话值的'Get'部分。

I visit the first page and it shows whatever value I put into the session. Hit the second page and you only get the 'Get ' part without any session value.

session_attributes总是有一个_token字段,我试过改变会话的名称并且仍然无法使会话工作。

session_attributes always has a _token field, I've tried changing the name of the session and the domain and still can't get sessions to work.

edit3:对于遇到此问题的任何人,我从未发现问题。我开始一个全新的项目,复制我的控制器和视图,重新创建我的路线文件,一切都正在工作 - 虽然我一半期待明天更新这篇文章,说它再次破碎!

edit3: for anyone who comes across this, I never identified the issue. I started a completely new project, copied my controllers and views across, recreated my routes file and everything is now working - although I'm half expecting to be updating this post tomorrow to say it's broken again!

推荐答案

我的问题是我在我的函数中有echo语句。

My problem was that I had echo statements in my function. It was keeping the session from being properly created/stored.

我在我的返回重定向之前有一个回显,所以重定向没有得到会话...

I had an echo before my 'return Redirect' so the redirect didn't get the session...

public function login()
{
    // auth
    if (Auth::attempt(Input::only('email', 'password'), true))
    {
        return Redirect::route('companies.index');
    }
    // failed -> back to login
    return Redirect::back()->withErrors(['email' => 'Login failed.'])->withInput();
}

详情: http://brainwashinc.com/2014/02/17/laravel-sessions-not-working-in-4-1/

这篇关于Laravel会话在每个负载重新生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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