« Back
in Laravel csrf session IE EDGE Laravel 5.2 p3p read.
CSRF tokenMismatch Exception / Session Error with Laravel on IE/Edge

CSRF tokenMismatch Exception / Session Error with Laravel on IE/Edge.

Recently, I used laravel 5.2 for a project and faced a weird error with handling cookies. The problem was with storing the cookies on Internet Explorer and Edge browsers. After doing a lot of search, I came to understand that the issue is basically with P3P Policy.

You could get a lot of answers if you do a search, but I got confused about how to implement those solutions. At last I was able to fix the issue using middleware, and thought of sharing the solution with the world.

All you need to do is create a middleware and include the same in all routes,

php artisan make:middleware IeFix

Above command will create a new middleware in the app/Http/Middlewares directory named IeFix.php. Now, we have to update the handle function in the IeFix.php.

public function handle($request, Closure $next)
    $response = $next($request);
    $response->header('P3P', 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
    return $response;

And then, update the Kernal.php in app/Http/ to register the middleware. You may either include the new middleware in Laravel's default middleware group web or add to route middleware and include in routes.

  1. Updating web middleware will look like,

    protected $middlewareGroups = [
         'web' => [
       // ..At the end of list....
          ],'api' => [
  2. And the other option, you can just add a new entry in $routeMiddleware array like,

    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
       'iefix' => \App\Http\Middleware\IeFix::class

    and then include this middleware in routes like,

    Route::group(['middleware' => ['web','iefix'],'prefix'=>'admin'], function () {
         // your routes here

That's It. Hope it helps!

Please comment below, if you have any questions or facing any issues. Thanks!