- Where does it create the token (what part of the code runs it)?
Going through the helpers file
/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
which had the definition of the helper method csrf_token() , which calls the token method on
/vendor/laravel/framework/src/Illuminate/Session/Store.php
and if you check start() , which calls regenerateToken() , if _token not been set, it will save a random 40-digit string for the session with the _token key
public function regenerateToken() { $this->put('_token', Str::random(40)); }
- Where is the marker stored after creation, in a cookie? In session? How can I extract and see what has been saved? Is this all actually controlled by session.php?
The token is stored in the session, it can be retrieved using session('_token') . Session expiration time is controlled in session.php using
'lifetime' => env('SESSION_LIFETIME', 120), 'expire_on_close' => false,
- What does this mean when I reload the page, is the token the same as session.php has 120 minutes default life?
If you /vendor/laravel/framework/src/Illuminate/Session/Store.php start() in /vendor/laravel/framework/src/Illuminate/Session/Store.php
public function start() { $this->loadSession(); if (! $this->has('_token')) { $this->regenerateToken(); } return $this->started = true; }
the token is restored if the session does not have _token . So _token will be the same until the session ends
linktoahref
source share