Laravel会话不仅仅在索引(登陆)页面上启动

时间:2014-07-24 12:02:48

标签: php session laravel

我在索引页面上有一个表单。当我刚刚访问该页面(清除所有cookie)时,浏览器上的会话cookie未设置。它只发生在索引页面上。抛出的错误是令牌不匹配。

注意 - 我在表单中有表单令牌代码,并且引发的错误是由会话引起的。

任何解决方案?谢谢

路线

Route::get('/',array('uses'=>'RootController@getIndex','as'=>'index'));

Route::group(array('before'=>'guest'),function(){
    Route::get('/account/create', array('uses' => 'AccountController@getCreate', 'as' => 'account_create' ));
    Route::get('/account/activate/{activation_code}', array('uses' => 'AccountController@getActivate', 'as' => 'account_activate' ));
    Route::get('/account/login', array('uses' => 'AccountController@getLogin', 'as' => 'login' ));
    Route::get('/account/forgot_password', array('uses' => 'AccountController@getForgotPassword', 'as' => 'forgot_password' ));
    Route::get('/account/recover/{activation_code}', array('uses' => 'AccountController@getRecover', 'as' => 'recover_account' ));

/*
CSRF Protection Group
*/
Route::group(array('before'=>'csrf'),function(){
    Route::post('/account/create', array('uses' => 'AccountController@postCreate'));
    Route::post('/account/login', array('uses' => 'AccountController@postLogin'));
    Route::post('/account/forgot_password', array('uses' => 'AccountController@postForgotPassword'));
    });

});

查看

{{ Form::open(array('action'=>'AccountController@postLogin','id'=>'sign-loginform','role'=>'form','class'=>'form-horizontal')) }}

{{ Form::token() }}

<div style="margin-bottom: 25px" class="input-group">
  <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
  <input id="login-username" type="text" class="form-control" name="email" value="" placeholder="Email">                                        
</div>

<div style="margin-bottom: 25px" class="input-group">
   <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
   <input id="login-password" type="password" class="form-control" name="password" placeholder="password">
</div>


<div style="margin-top:10px" class="form-group">
   <div class="col-sm-12 controls">
       <button id="submit_button" name="submit_button" class="btn btn-primary">Login</button>
       <a id="btn-fblogin" href="{{ URL::route('account_create') }}" class="btn btn-success">Register</a>
    </div>
</div>


{{ Form::close() }}

控制器

public function getIndex(){
    return View::make('root.index')
        ->with('page','index');
}`

1 个答案:

答案 0 :(得分:0)

小心,因为:

{{Form::open()}}

创建表单的开头标记,操作,方法和表单属性,但在开始标记关闭后立即添加隐藏的标记字段。

{{Form::token()}}

仅创建隐藏令牌输入字段。

猜猜看,你创建了两次csrf令牌。