Laravel 5.5 login and register page says:The page has expired due to inactivity.[TokenMismatchException]

后端 未结 17 3192
你的背包
你的背包 2020-12-09 05:11

I just created a new project of laravel version 5.5 with the laravel installer.And run the command \"php artisan make:auth\".The views and controller are generated

相关标签:
17条回答
  • 2020-12-09 05:49

    i think you missed csrf token.

    dont forget to use {!! csrf_field() !!}

    0 讨论(0)
  • 2020-12-09 05:51

    I was only testing post requests for my api and came across the same issue. I resolved it by adding my route to the Middleware VerifyCsrfToken's $except array i.e. go to app/Http/Middleware/VerifyCsrfToken and add

    protected $except = [
            'your/route'
    ];
    

    But if your requests are from some front-end platform or views, it's advisable to add {{ csrf_field() }} in the form that sends the request.

    0 讨论(0)
  • 2020-12-09 05:53

    I had the same issue and it was because I was using virtualhost and I setup below variable to mydomain.com. in config/session.php file

    'domain' => env('SESSION_DOMAIN', 'mydomain.com'),
    

    When I changed it to null then it started working

    'domain' => env('SESSION_DOMAIN', 'null'),
    

    I don't know what is the reason behind it but it is working fine now.

    0 讨论(0)
  • 2020-12-09 05:53

    It appears to be permission settings on either storage and/or bootstrap/cache.

    I'm using a Cloudways server. I reset permissions on my server under Application Settings and it now works. On my local development server the equivalent was to set chmod 777 on storage.. I had used 755 previously and the error persisted.

    0 讨论(0)
  • 2020-12-09 05:56

    I had the same problem on localhost:8000 (php artisan serve). Maybe it's coincidence, but try on "clean browser" , other than you used with previous development. For me it worked.

    It seems that the problem is with cookies from development with previous Laravel versions, on the same url.

    0 讨论(0)
  • 2020-12-09 05:56

    This issue is mainly caused because you don't have the csrf token in your form. During csrf token verification it fails, that's why you are getting this page. Laravel generally needs csrf token in all its forms. You can add a csrf token simply by adding this inside the form.

     {{ csrf_field() }}
    

    Another method of doing this is you can exclude your route in the verifycsrftoken middleware.

    Just add a protected field in the middleware with your route name.

    protected $except=[
                        '1st route',
                        '2nd route',
                        .
                        .
                      ];
    

    This should work.

    0 讨论(0)
提交回复
热议问题