Laravel cannot get session value for cross-domain POST request when csrf is turned off

Front end: VUE back end: Laravel

  1. my requirement is that the verification code generated at the backend is stored in the session, and then the verification code in the session is compared with the verification code sent from the front end when the frontend post request is made, but the session value cannot be obtained at this time

2. After searching for it, I found that it was due to the closure of csrf, but my project was separated from the front and back end and was originally a cross-site request. no, no, no. If you don"t turn off csrf, you won"t report mismatchToken"s error
ask God to have a look

Mar.04,2021

Laravel saves the CSRF token to a Cookie named XSRF-TOKEN, which you can use to set the X-XSRF-TOKEN request header. Some JavaScript frameworks, such as Angular, will automatically set this value for you, and basically you don't need to set this value manually.


I think this is because the sessionid of each request is different and the session value cannot be obtained.
has nothing to do with csrf.

Menu