Php Laravel会话突然被破坏

Php Laravel会话突然被破坏,php,session,laravel,laravel-4,Php,Session,Laravel,Laravel 4,我有一个多页的表格,用于处理体育赛事注册。我们有很多用户(约15%的用户,独立于平台/浏览器)遇到以下错误: 该表格包含以下页面: 开始 细节 团队 阶级 批处理 商品 调查 完整的 在每一页上,我们检查会话是否包含上一页的数据。如果没有,我们就把他引回去 遇到的问题是15%组在第4步输入数据后被重定向回 这可能意味着会话/数据在步骤4的存储函数中被破坏,但我不知道如何/为什么/在哪里。但是,如果这是一个问题,那么只有15%的用户会遇到这个问题是没有意义的。此外,经过数小时的尝试,我们无法重现此

我有一个多页的表格,用于处理体育赛事注册。我们有很多用户(约15%的用户,独立于平台/浏览器)遇到以下错误:

该表格包含以下页面:

  • 开始
  • 细节
  • 团队
  • 阶级
  • 批处理
  • 商品
  • 调查
  • 完整的
  • 在每一页上,我们检查会话是否包含上一页的数据。如果没有,我们就把他引回去

    遇到的问题是15%组在第4步输入数据后被重定向回

    这可能意味着会话/数据在步骤4的存储函数中被破坏,但我不知道如何/为什么/在哪里。但是,如果这是一个问题,那么只有15%的用户会遇到这个问题是没有意义的。此外,经过数小时的尝试,我们无法重现此错误

    我知道会话被完全刷新/破坏,因为用户被级联回:showBatchPage将用户还原回showClassPage、showClassPage还原回showMembersPage、showMembersPage还原回showStartPage等。我们还记录这些还原

    我的代码如下所示:

    <?php
    
    public function saveClassPage($slug)
    {
        $rules = [];
        $messages = [];
        $memberClasses = [];    
    
        // prepare solo error messages    
        foreach (Session::get('entry.members') as $id => $member)
        {
            if (!isset($member['group'])) {
                $rules["class.{$id}"] = 'required';
                $messages["class.{$id}.required"] = "Please select a class for member {$member['firstname']} {$member['lastname']}";
            }
        }
    
        // prepare team error messages
        foreach (Session::get('entry.groups', []) as $id => $group)
        {
            $rules["group.{$id}"] = 'required';
            $messages["group.{$id}.required"] = "Please select a class for group {$group['name']}";
        }
    
        $validator = Validator::make(Input::all(), $rules, $messages);
    
        // loop trough solo members and set class
        foreach (Input::get('class', []) as $i => $class)
        {
            Session::put("entry.members.{$i}.class", $class);
    
            // if there is only one class in the batch, assign it
            $memberClasses[$i] = ClassModel::find($class);
            if ($memberClasses[$i]->batches()->count() < 2) {
                Session::put("entry.members.{$i}.batch", $memberClasses[$i]->batches()->first()->id);
            }
        }
    
        // loop trough teams and set class
        foreach (Input::get('group', []) as $i => $class)
        {
            foreach (Session::get("entry.groups.{$i}.members", []) as $id)
            {
                Session::put("entry.members.{$id}.class", $class);
    
                // if there is only one class in the batch, assign it
                $memberClasses[$id] = ClassModel::find($class);
                if ($memberClasses[$id]->batches()->count() < 2) {
                    Session::put("entry.members.{$i}.batch", $memberClasses[$id]->batches()->first()->id);
                }
            }
            Session::put("entry.groups.{$i}.class", $class);
        }
    
        $allClassesAreEmpty = true;
        foreach ($memberClasses as $class)
        {
            if ($class->batches()->count() > 1) {
                $allClassesAreEmpty = false;
                break;
            }
        }
    
        if ($validator->passes()) {
            // skip batch page if there is only one batch
            if ($allClassesAreEmpty) {
                return Redirect::action('EventEntryController@showExtrasPage', array('slug' => $slug));
            } else {
                return Redirect::action('EventEntryController@showBatchPage', array('slug' => $slug));
            }
        }
    
        return Redirect::action('EventEntryController@showClassPage', array('slug' => $slug))->withErrors($validator);
    }
    
    public function showBatchPage($slug)
    {
        $firstMember = head( Session::get('entry.members', []) );
    
        if (!isset($firstMember['class'])) {
            Log::info('showBatchPage@revertToClass');
    
            return Redirect::action('EventEntryController@showClassPage', array('slug' => $slug));
        }
    
        // other stuff (preparing view data etc.)
    
        return View::make('entry/batch', $viewData);
    }
    

    假设您正在使用本地设备(Dev),以避免与使用相同默认
    会话Cookie名称和相同
    域的其他Laravel应用程序混淆:

  • 清除所有与Laravel应用程序用于故障排除的域相关的
    浏览器cookie
  • 将您的
    会话Cookie名称
    更改为更唯一的名称(如果需要,则不带下划线)

  • 如果您使用默认会话驱动程序
    文件
    ,请确保您对文件夹
    app/storage

    具有写入权限,是否可以发布所有app/config/session.php代码?是否尝试过切换会话类型?也许是数据库,或者安装memcache?不,还没有。你认为这有什么关系?由于问题发生在同一位置,而且不总是(如果我完全复制受影响的用户的操作,我一点问题都没有),对我来说,这不是会话提供程序的问题,而是排除问题。如果问题发生在DB会话中,那么您知道它不是您的文件会话。但目前你还不确定这一点——这可能是最简单的改变。哦,还有一件事——把你的cookie改成没有下划线的东西——一些旧的IE浏览器不喜欢带下划线的cookie。已经尝试过了,但没有用。将cookie名称更改为唯一名称,然后更改为db driver以排除文件系统错误。仍然没有发现问题,仍然无法重现。
    <?php
    
    return array(
    
        /*
        |--------------------------------------------------------------------------
        | Default Session Driver
        |--------------------------------------------------------------------------
        |
        | This option controls the default session "driver" that will be used on
        | requests. By default, we will use the lightweight native driver but
        | you may specify any of the other wonderful drivers provided here.
        |
        | Supported: "file", "cookie", "database", "apc",
        |            "memcached", "redis", "array"
        |
        */
    
        'driver' => 'file',
    
        /*
        |--------------------------------------------------------------------------
        | Session Lifetime
        |--------------------------------------------------------------------------
        |
        | Here you may specify the number of minutes that you wish the session
        | to be allowed to remain idle before it expires. If you want them
        | to immediately expire on the browser closing, set that option.
        |
        */
    
        'lifetime' => 120,
    
        'expire_on_close' => false,
    
        /*
        |--------------------------------------------------------------------------
        | Session File Location
        |--------------------------------------------------------------------------
        |
        | When using the native session driver, we need a location where session
        | files may be stored. A default has been set for you but a different
        | location may be specified. This is only needed for file sessions.
        |
        */
    
        'files' => storage_path().'/sessions',
    
        /*
        |--------------------------------------------------------------------------
        | Session Database Connection
        |--------------------------------------------------------------------------
        |
        | When using the "database" or "redis" session drivers, you may specify a
        | connection that should be used to manage these sessions. This should
        | correspond to a connection in your database configuration options.
        |
        */
    
        'connection' => null,
    
        /*
        |--------------------------------------------------------------------------
        | Session Database Table
        |--------------------------------------------------------------------------
        |
        | When using the "database" session driver, you may specify the table we
        | should use to manage the sessions. Of course, a sensible default is
        | provided for you; however, you are free to change this as needed.
        |
        */
    
        'table' => 'sessions',
    
        /*
        |--------------------------------------------------------------------------
        | Session Sweeping Lottery
        |--------------------------------------------------------------------------
        |
        | Some session drivers must manually sweep their storage location to get
        | rid of old sessions from storage. Here are the chances that it will
        | happen on a given request. By default, the odds are 2 out of 100.
        |
        */
    
        'lottery' => array(2, 100),
    
        /*
        |--------------------------------------------------------------------------
        | Session Cookie Name
        |--------------------------------------------------------------------------
        |
        | Here you may change the name of the cookie used to identify a session
        | instance by ID. The name specified here will get used every time a
        | new session cookie is created by the framework for every driver.
        |
        */
    
        'cookie' => 'laravel_session',
    
        /*
        |--------------------------------------------------------------------------
        | Session Cookie Path
        |--------------------------------------------------------------------------
        |
        | The session cookie path determines the path for which the cookie will
        | be regarded as available. Typically, this will be the root path of
        | your application but you are free to change this when necessary.
        |
        */
    
        'path' => '/',
    
        /*
        |--------------------------------------------------------------------------
        | Session Cookie Domain
        |--------------------------------------------------------------------------
        |
        | Here you may change the domain of the cookie used to identify a session
        | in your application. This will determine which domains the cookie is
        | available to in your application. A sensible default has been set.
        |
        */
    
        'domain' => null,
    
        /*
        |--------------------------------------------------------------------------
        | HTTPS Only Cookies
        |--------------------------------------------------------------------------
        |
        | By setting this option to true, session cookies will only be sent back
        | to the server if the browser has a HTTPS connection. This will keep
        | the cookie from being sent to you if it can not be done securely.
        |
        */
    
        'secure' => false,
    
    );