CSRF Token is against Cross-Scripting, so against bot, isn't it ? There is a solution against bot : CAPTCHA.
Why not ask the user to prove that he's not a bot by displaying a captha in a modal, then refresh the token with an AJAX Request?
renewing csrf in a fixed period of time doesn't work well. there are so may reasons users open multiple tabs on their browser, renewing csrf breaks connectivity of other tabs.
I want to expire user session after 20 minute
but issue is that i am calling ajax on every 5 second of interval and just because of that session is being updated and user is not logout after even after idleness of 20 minutes.
Does anyone knows any way that not update session variable on ajax call.
Here is my session.php file confuguration
'lifetime' =>20,
'expire_on_close' => false,
The solution that worked for me when user leaves the form for awhile with CSRF enabled for every request is to make a GET request in AJAX Success when request fails because token has expired.
Then have a hidden field that continue to be updated with latest token and if at the time of making request it has expired you make a GET REQUEST to fetch latest TOKEN and then evoke click event on function that submits form which means the function has to be passed "this" or ID as part parameter.This makes the user not to realize the process of renewing token in the background