Laravel 4.2 Generate CSRF Token with expiration time

739 Views Asked by At

I need to create csrf token inside the controller with certain expiration time.

return csrf_token();

I tried to do like this csrf_token('300')

But i am not sure whether it sets the csrf_token expiration time for 300 seconds.

Does this way, csrf_token('300') the right way to generate csrf_token with expiration time in Laravel 4.2 ?

1

There are 1 best solutions below

2
On

Would say this does not work, if you check the function:

    //framework/src/Illuminate/Support/helpers.php
    function csrf_token()
    {
        $session = app('session');

        if (isset($session))
        {
            return $session->getToken();
        }

        throw new RuntimeException("Application session store not set.");
    }

It has no parameters. But you can implement your own csrf_token helper.

In the current implementation, the token should be renewed with a new session. Maybe you can regenerate session id to get a new csrf token.

https://laracasts.com/discuss/channels/general-discussion/session-lifetime-timeout-and-csrf-token-mismatch