Yes of course session is related to csrf.
Token in session has to match forms submitted token. These are maybe expired tokens. You could setup a redirect.
The best practice is have users logout.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a site with hundreds of daily users. 99% of the time, CSRF tokens works just fine. Very occasionally (not even once per day), I'll get a Illuminate\Session\TokenMismatchException CSRF token mismatch error. How can I debug this further, since it's entirely handled by Laravel? Is there a way to find out when a session was issued and when it expires? Sessions are one of those magical things and the docs don't mention it.
session.lifetime is set to 43800, so a month. I wasn't sure if the CSRF was related to that. So if it happens to expire while the user is on the application, they just have to reload the page? Seems like a strange way for Laravel to handle this.
Update since this is still an issue: I added some logging and when this does happen - which is rare - I confirmed that:
X-CSRF-TOKEN header doesn't match session()->token()
resources/js/bootstrap.js file includes the Axios HTTP library which will automatically send the X-XSRF-TOKEN header for you." I confirmed this by printing window.axios.defaults.headers.common['X-CSRF-TOKEN'] to the console. It matched the value in <meta name="csrf-token" content="{{ csrf_token() }}"> (from the CSRF page)SESSION_LIFETIME set to 43800, about a monthSo here's where I'm stuck. The header should match, and does most of the time (99%), but occasionally, it does not. I am unsure how to fix or debug this, as none of it involves my own code.
Please or to participate in this conversation.