F
F
freeeeez2017-02-10 14:37:35
Laravel
freeeeez, 2017-02-10 14:37:35

How to deal with the error TokenMismatchException in VerifyCsrfToken.php?

The error "TokenMismatchException in VerifyCsrfToken.php" occurs if, after a long downtime (for example, after a weekend), an AJAX request to the controller is made from the open page. It turns out that at this time the token is already different, as it usually happens if the session lifetime is set to the standard 120 minutes. However, the session.php file settings contain the following line:
'expire_on_close' => true
As I understand it, this construction should ignore the 'lifetime' => 120 setting and close the session and token when the browser is closed, but this does not work. Initially it was false - the same thing. How can I force the token to be stored until the browser is closed, or if this is not possible, how to send back a new token in an AJAX request and send another AJAX with a new token?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2017-02-10
@freeeeez

/**
     * Get the cookie lifetime in seconds.
     *
     * @return \DateTimeInterface
     */
    protected function getCookieExpirationDate()
    {
        $config = $this->manager->getSessionConfig();

        return $config['expire_on_close'] ? 0 : Carbon::now()->addMinutes($config['lifetime']);
    }

This is just a cookie setting. And the PHP session also has its own lifetime, which is set in lifetime.
You can write something like 525960 there (the average number of minutes per year for 3 ordinary years and one leap year) - the year will be stored.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question