2016-06-14 26 views
0

ログインしようとしているときにVerifyCsrfTokenのTokenMismatchExceptionを取得しています。クッキーが作成されていないことが表示されます。考えられる原因は何でしょうか?以下はLaravelのTokenMismatchException:ログインできません。

観測されています

< input type="hidden" name="_token" value="{{ csrf_token() }}">   

をまだ問題が残っている:

1)が追加されました。

'driver' => env('SESSION_DRIVER', 'cookie'), 

'driver' => env('SESSION_DRIVER', 'file'), 

が、まだ問題が残っている:

2)からsessions.phpに変更しました。

3)私はすべてのブラウザで試しましたが、まだ運がありません。

4)同じコードベースが他のシステムでは正常に動作していますが、私のシステムでは正常に動作していません。また、私はウィンドウを再インストールしましたが、それでも同じ問題です。

助けてください

Stack trace: 
#0 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#1 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
#2 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#3 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#4 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
#5 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#6 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#7 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
#8 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#9 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#10 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
#11 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#12 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#13 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
#14 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#15 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#16 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
#17 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#18 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#19 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
#20 D:\Development\Code\biz\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) 
#21 D:\Development\Code\biz\public\index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) 
#22 D:\Development\Code\biz\server.php(21): require_once('D:\\Development\\...') 
#23 {main} 

.env

APP_ENV=local 
APP_DEBUG=true 
APP_KEY=fbq7vdvBI18IzYMLDxi9fmvSUaXuxaNg 

APP_TIMEZONE=Asia/Kolkata 

DB_CONNECTION=mysql 
DB_HOST=localhost 
DB_DATABASE=tnpdb 
DB_USERNAME=********* 
DB_PASSWORD=********* 
DB_STRICT=true 
DB_COLLATION=utf8_general_ci 

CACHE_DRIVER=file 
SESSION_DRIVER=file 
QUEUE_DRIVER=sync 

MAIL_DRIVER=smtp 
MAIL_HOST=******.*******************.net 
MAIL_PORT=587 
MAIL_USERNAME=*******@******.com 
MAIL_PASSWORD=********* 
MAIL_ENCRYPTION=tls 
MAIL_FROM_ADDRESS=*******@*******.com 
MAIL_FROM_NAME=********* 

WKHTMLTOPDF_BIN=/usr/local/bin/wkhtmltopdf 
WKHTMLTOIMG_BIN=/usr/local/bin/wkhtmltoimage 

sessions.php

<?php 

return [ 

/* 
|-------------------------------------------------------------------------- 
| 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' => env('SESSION_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' => 15, 

'expire_on_close' => false, 

/* 
|-------------------------------------------------------------------------- 
| Session Encryption 
|-------------------------------------------------------------------------- 
| 
| This option allows you to easily specify that all of your session data 
| should be encrypted before it is stored. All encryption will be run 
| automatically by Laravel and you can use the Session like normal. 
| 
*/ 

'encrypt' => 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('framework/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' => [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' => env('HTTPS_ONLY_COOKIES', false), 

]; 

VerifyCsrfToken.php

<?php 

namespace App\Http\Middleware; 

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; 

class VerifyCsrfToken extends BaseVerifier { 
/** 
* The URIs that should be excluded from CSRF verification. 
* 
* @var array 
*/ 
protected $except = [ 
    '*****response', 
    '*****response', 
    '*****response', 
    'v1/*', 
    ]; 
} 
+0

は、私は彼らに –

+0

を表示しますセッションドライバーをCookieに変更してテストしても – Abhi1988

+0

トンを追加している私達にあなたの.envとあなたのsession.php設定ファイル –

答えて

0

オーケー、あなたがこのようなWebミドルウェアの内部で、あなたのルートを作る必要があります。

Route::group(['middleware' => ['web']], function() { 
     Route::get('/','[email protected]'); 
    }); 

セッションとトークンミドルウェアは、そのような同じミドルウェア・グループ「WEB」であるため。

protected $middlewareGroups = [ 
     'web' => [ 
      \App\Http\Middleware\EncryptCookies::class, 
      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
      \Illuminate\Session\Middleware\StartSession::class, 
      \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
      \App\Http\Middleware\VerifyCsrfToken::class, 

     ], 
    ]; 
+0

私たちはlaravel 5.1を持っています。上記のコードを記述したときにこのエラーが発生する:「Container.php行のReflectionException: クラスのWebが存在しません」 – Abhi1988

+0

コントローラの名前を教えてもらえますか? –

関連する問題